+ Post New Thread
Results 1 to 10 of 10
Windows Thread, Batch file to create folders in Technical; I hate writing scripts or batch files because I always break things. Can anybody help me make a script that ...
  1. #1
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    790
    Thank Post
    136
    Thanked 66 Times in 58 Posts
    Rep Power
    19

    Batch file to create folders

    I hate writing scripts or batch files because I always break things. Can anybody help me make a script that makes a folder inside users home directories.

    For example. The students home folder is C:\students\username on the server. What I need to make is a folder inside the \username folder so,
    C:\students\username\newfolder
    I have over 500 accounts to do so I was hoping that I could use some sort of %username% type command or wildcard. I've Googled but im all out of Google Fu today.

  2. #2

    Join Date
    Dec 2009
    Posts
    250
    Thank Post
    5
    Thanked 28 Times in 26 Posts
    Rep Power
    14
    You could use Group Policy Preference mode, User Configuration to create a folder.

    Do the users get their home directory mapped as a particular drive? Say it Maps to H:\ you could set the GPP to create H:\new folder

  3. #3
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    790
    Thank Post
    136
    Thanked 66 Times in 58 Posts
    Rep Power
    19
    Arh yes I could but I've not got GPP on my 2003 R2 server.

  4. #4
    DT2
    DT2 is offline
    DT2's Avatar
    Join Date
    May 2011
    Location
    Lakeville, Carleton County, New Brunswick
    Posts
    695
    Thank Post
    140
    Thanked 198 Times in 139 Posts
    Rep Power
    74
    Quote Originally Posted by Gaz View Post
    I hate writing scripts or batch files because I always break things. Can anybody help me make a script that makes a folder inside users home directories.

    For example. The students home folder is C:\students\username on the server. What I need to make is a folder inside the \username folder so,
    C:\students\username\newfolder
    I have over 500 accounts to do so I was hoping that I could use some sort of %username% type command or wildcard. I've Googled but im all out of Google Fu today.
    CLS
    ::variables
    set name=c:\Students\
    ::commands
    md %name%\%username%\nameoffolder

    add pause if you want it to halt before exiting, else exit.

    create a .bat and set to run at logon.

    Should work.




    Also, if you find the %username% doesn't work (as it pulls the user of the current process and isnt always correct), then use this:

    for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set _currdomain_user=%%c
    for /f "TOKENS=1,2 DELIMS=\" %%a in ("%_currdomain_user%") do set _currdomain=%%a & set _curruser=%%b
    Last edited by DT2; 28th November 2012 at 04:08 PM.

  5. #5

    Join Date
    Dec 2009
    Posts
    250
    Thank Post
    5
    Thanked 28 Times in 26 Posts
    Rep Power
    14
    You shouldn't need a 2008 server. GPP's apply to all devices with XP SP3 and above I believe. You should be able to run a Win 7 pc with the RSAT tools installed and this should let you managed these settings :-)

  6. #6
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    790
    Thank Post
    136
    Thanked 66 Times in 58 Posts
    Rep Power
    19
    for /f "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq explorer.exe" /FO LIST /V') do if /i "%%a %%b"=="User Name:" set _currdomain_user=%%c
    for /f "TOKENS=1,2 DELIMS=\" %%a in ("%_currdomain_user%") do set _currdomain=%%a & set _curruser=%%b

    Just the kinda stuff I was hoping to avoid.

    The .bat file sounds promising. If its to run at logon though I'd would need the network map so
    set name=h:\domaincontroller\students\%username%\newfo lder
    md %name%\%username%\nameoffolder

    Sould that work?

  7. #7

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,272
    Thank Post
    613
    Thanked 1,567 Times in 1,407 Posts
    Rep Power
    412
    If not exist h:\newfolder mkdir h:\newfolder

    in a logon script assuming you map h: to their home folder.

    Ben

  8. #8
    DT2
    DT2 is offline
    DT2's Avatar
    Join Date
    May 2011
    Location
    Lakeville, Carleton County, New Brunswick
    Posts
    695
    Thank Post
    140
    Thanked 198 Times in 139 Posts
    Rep Power
    74
    Yeah, you can just stick net use in there in stead of the %name% variable.

    net use H: \\server\share\%username%
    md H:\newfolder
    If H: is already mapped then it's even easier, just omit the net use command.

  9. #9
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    790
    Thank Post
    136
    Thanked 66 Times in 58 Posts
    Rep Power
    19
    Arh I see. Yes H:\ is their home folder.

    Oh how much easier this would have been if I could have just typed "mkdir c:\students\*\newfolder" where * is the random folder/username. It works on files, why not folders too.

  10. #10
    DT2
    DT2 is offline
    DT2's Avatar
    Join Date
    May 2011
    Location
    Lakeville, Carleton County, New Brunswick
    Posts
    695
    Thank Post
    140
    Thanked 198 Times in 139 Posts
    Rep Power
    74
    Tell me about it.....
    But, I suppose if it was easy it'd be boring and we'd be paid peanuts..... Oh, wait.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 12
    Last Post: 29th September 2012, 09:27 PM
  2. Replies: 4
    Last Post: 6th November 2008, 01:42 PM
  3. Replies: 1
    Last Post: 21st January 2007, 02:51 PM
  4. prezzie batch file to collect dps logs
    By russdev in forum ICT KS3 SATS Tests
    Replies: 4
    Last Post: 16th May 2006, 12:16 PM
  5. Replies: 6
    Last Post: 20th October 2005, 06:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •