+ 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
    478
    Thank Post
    82
    Thanked 44 Times in 40 Posts
    Rep Power
    12

    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. IDG Tech News
  3. #2

    Join Date
    Dec 2009
    Posts
    171
    Thank Post
    4
    Thanked 20 Times in 19 Posts
    Rep Power
    10
    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

  4. #3
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    478
    Thank Post
    82
    Thanked 44 Times in 40 Posts
    Rep Power
    12
    Arh yes I could but I've not got GPP on my 2003 R2 server.

  5. #4
    DT2
    DT2 is offline
    DT2's Avatar
    Join Date
    May 2011
    Location
    the locals call it buttf*** nowhere...
    Posts
    666
    Thank Post
    120
    Thanked 188 Times in 131 Posts
    Rep Power
    71
    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.

  6. #5

    Join Date
    Dec 2009
    Posts
    171
    Thank Post
    4
    Thanked 20 Times in 19 Posts
    Rep Power
    10
    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 :-)

  7. #6
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    478
    Thank Post
    82
    Thanked 44 Times in 40 Posts
    Rep Power
    12
    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?

  8. #7

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    11,327
    Thank Post
    419
    Thanked 1,160 Times in 1,051 Posts
    Rep Power
    263
    If not exist h:\newfolder mkdir h:\newfolder

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

    Ben

  9. #8
    DT2
    DT2 is offline
    DT2's Avatar
    Join Date
    May 2011
    Location
    the locals call it buttf*** nowhere...
    Posts
    666
    Thank Post
    120
    Thanked 188 Times in 131 Posts
    Rep Power
    71
    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.

  10. #9
    Gaz
    Gaz is offline

    Join Date
    Feb 2011
    Location
    Preston
    Posts
    478
    Thank Post
    82
    Thanked 44 Times in 40 Posts
    Rep Power
    12
    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.

  11. #10
    DT2
    DT2 is offline
    DT2's Avatar
    Join Date
    May 2011
    Location
    the locals call it buttf*** nowhere...
    Posts
    666
    Thank Post
    120
    Thanked 188 Times in 131 Posts
    Rep Power
    71
    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
  •