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 ...
-
28th November 2012, 03:35 PM #1 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.
-
-
IDG Tech News
-
28th November 2012, 03:48 PM #2
- 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
-
-
28th November 2012, 03:56 PM #3 Arh yes I could but I've not got GPP on my 2003 R2 server.
-
-
28th November 2012, 03:58 PM #4 
Originally Posted by
Gaz
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.
-
-
28th November 2012, 04:02 PM #5
- 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 :-)
-
-
28th November 2012, 04:29 PM #6 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?
-
-
28th November 2012, 04:33 PM #7 If not exist h:\newfolder mkdir h:\newfolder
in a logon script assuming you map h: to their home folder.
Ben
-
-
28th November 2012, 04:36 PM #8 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.
-
-
28th November 2012, 04:46 PM #9 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.
-
-
28th November 2012, 04:49 PM #10 Tell me about it.....
But, I suppose if it was easy it'd be boring and we'd be paid peanuts..... Oh, wait.
-
SHARE: 
Similar Threads
-
By MarsRed in forum Windows 7
Replies: 12
Last Post: 29th September 2012, 09:27 PM
-
By jman167 in forum Windows
Replies: 4
Last Post: 6th November 2008, 01:42 PM
-
Replies: 1
Last Post: 21st January 2007, 02:51 PM
-
By russdev in forum ICT KS3 SATS Tests
Replies: 4
Last Post: 16th May 2006, 12:16 PM
-
By tosca925 in forum Windows
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
-
Forum Rules