![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Create subfolders and copy a file Hey there I hope someone can help me with a script that can create a subfolder and copy a file from another folder into the newly created folder, but only if that folder and file doesn’t exist. More specific, I have all our user home folders in 5 different subfolders, it looks something like this: d:\users\dep1\"accountname" \dep2\"accountname" And so on. The script needs to check if a folder called template exists in each "accountname" folder. If it doesn’t exist it needs to create it and copy a file to it (d:\template\normal.dot) I have tried searching through the forum, and also on the internet, but with no luck. I hope someone here can help me. -- /Jan |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Create subfolders and copy a file What you want is all available with the FileSystemObject object. If you don't have the WSH help file you should download that. http://www.microsoft.com/downloads/d...C48-207D-4BE1- 8A76-1C4099D7BBB9&displaylang=en Methods in FSO: FileExists - tests whether a file exists. FolderExists - tests whether a folder exists. CopyFile - cpies a single file to another location. With the folder *object* you can access the subfolders and files, as folder and file objects: Set oFol = FSO.GetFolder("C:\folder1") Set SubFols = oFol.SubFolders For each SubFol in SubFols '-- access the subfolder folder object here Next Quote: > Hey there > > I hope someone can help me with a script that can create a subfolder and > copy a file from another folder into the newly created folder, but only if > that folder and file doesnâ?Tt exist. > > More specific, I have all our user home folders in 5 different subfolders, > it looks something like this: > > d:\users\dep1\"accountname" > \dep2\"accountname" > > And so on. > > The script needs to check if a folder called template exists in each > "accountname" folder. If it doesnâ?Tt exist it needs to create it and copy Quote: > file to it (d:\template\normal.dot) > > I have tried searching through the forum, and also on the internet, but Quote: > no luck. > > I hope someone here can help me. > > -- > /Jan |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Create subfolders and copy a file Janc schreef: Quote: > Hey there > > I hope someone can help me with a script that can create a subfolder and > copy a file from another folder into the newly created folder, but only if > that folder and file doesn’t exist. > > More specific, I have all our user home folders in 5 different subfolders, > it looks something like this: > > d:\users\dep1\"accountname" > \dep2\"accountname" > > And so on. > > The script needs to check if a folder called template exists in each > "accountname" folder. If it doesn’t exist it needs to create it and copy a > file to it (d:\template\normal.dot) > > I have tried searching through the forum, and also on the internet, but with > no luck. > > I hope someone here can help me. > if not exist d:\users\dep1\account ( mkdir d:\users\dep1\account\template && copy d:\template\normal.dot d:\users\dep1\account\template ) -- Luuk |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Create subfolders and copy a file "Luuk" <luuk@xxxxxx> wrote in message news:e50446-cc2.ln1@xxxxxx Quote: > Janc schreef: Quote: >> Hey there >> >> I hope someone can help me with a script that can create a subfolder and >> copy a file from another folder into the newly created folder, but only >> if that folder and file doesn't exist. >> >> More specific, I have all our user home folders in 5 different >> subfolders, it looks something like this: >> >> d:\users\dep1\"accountname" >> \dep2\"accountname" >> >> And so on. The script needs to check if a folder called template exists >> in each "accountname" folder. If it doesn't exist it needs to create it >> and copy a file to it (d:\template\normal.dot) >> >> I have tried searching through the forum, and also on the internet, but >> with no luck. >> >> I hope someone here can help me. >> > > if not exist d:\users\dep1\account ( > mkdir d:\users\dep1\account\template && > copy d:\template\normal.dot d:\users\dep1\account\template ) vbscript. Still, for something like this that would be my tool of choice. Try putting the following ina .cmd file (set test=ECHO/) rem (set test=) for /d %%D in (d:\users\*.*) do call:dept "%%~D" pause & goto:Eof :dept for /d %%U in ("%%~1\*.*") do call:user "%%~U" goto:eof :user if not exist "%%~1\template" ( %test% md "%%~1\template" %test% copy d:\template\normal.dot "%%~1\template" ) goto:eof If you are happy with all of the md and copy commands that this displays, change this line: rem (set test=) to this (set test=) /Al |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Create subfolders and copy a file Thanks all for replies Your script didnt work Al so i modified it so it worked. Thanks for it anyway though, it was a great help. The script i got working is here: (set test=ECHO/) rem (set test=) for /d %%D in (d:\users\*.*) do call:dept "%%~D" pause & goto:Eof :dept for /d %%U in ("%~1\*.*") do call:user "%%~U" goto:eof :user if not exist "%~1\template" ( %test% md "%~1\template" ) if not exist "%~1\template\normal.dot" ( %test% copy d:\template\normal.dot "%~1\template" ) goto:eof If you are happy with all of the md and copy commands that this displays, change this line: rem (set test=) to this (set test=) "Al Dunbar" wrote: Quote: > > "Luuk" <luuk@xxxxxx> wrote in message > news:e50446-cc2.ln1@xxxxxx Quote: > > Janc schreef: Quote: > >> Hey there > >> > >> I hope someone can help me with a script that can create a subfolder and > >> copy a file from another folder into the newly created folder, but only > >> if that folder and file doesn't exist. > >> > >> More specific, I have all our user home folders in 5 different > >> subfolders, it looks something like this: > >> > >> d:\users\dep1\"accountname" > >> \dep2\"accountname" > >> > >> And so on. The script needs to check if a folder called template exists > >> in each "accountname" folder. If it doesn't exist it needs to create it > >> and copy a file to it (d:\template\normal.dot) > >> > >> I have tried searching through the forum, and also on the internet, but > >> with no luck. > >> > >> I hope someone here can help me. > >> > > > > if not exist d:\users\dep1\account ( > > mkdir d:\users\dep1\account\template && > > copy d:\template\normal.dot d:\users\dep1\account\template ) > You could have mentioned that yours is a batch script rather than a > vbscript. Still, for something like this that would be my tool of choice. > Try putting the following ina .cmd file > > (set test=ECHO/) > rem (set test=) > for /d %%D in (d:\users\*.*) do call:dept "%%~D" > pause & goto:Eof > > :dept > for /d %%U in ("%%~1\*.*") do call:user "%%~U" > goto:eof > > :user > > if not exist "%%~1\template" ( > %test% md "%%~1\template" > %test% copy d:\template\normal.dot "%%~1\template" > ) > goto:eof > > If you are happy with all of the md and copy commands that this displays, > change this line: > > rem (set test=) > > to this > > (set test=) > > > /Al > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Create subfolders and copy a file "JanC" <JanC@xxxxxx> wrote in message news:4B397925-3690-400A-8DA7-9C9E68CD653F@xxxxxx Quote: > Thanks all for replies > > Your script didnt work Al so i modified it so it worked. Thanks for it > anyway though, it was a great help. /Al Quote: > The script i got working is here: > > (set test=ECHO/) > rem (set test=) > for /d %%D in (d:\users\*.*) do call:dept "%%~D" > pause & goto:Eof > > :dept > for /d %%U in ("%~1\*.*") do call:user "%%~U" > goto:eof > > :user > > if not exist "%~1\template" ( > %test% md "%~1\template" > ) > if not exist "%~1\template\normal.dot" ( > %test% copy d:\template\normal.dot "%~1\template" > ) > goto:eof > > If you are happy with all of the md and copy commands that this displays, > change this line: > > rem (set test=) > > to this > > (set test=) > > > > > > "Al Dunbar" wrote: > Quote: >> >> "Luuk" <luuk@xxxxxx> wrote in message >> news:e50446-cc2.ln1@xxxxxx Quote: >> > Janc schreef: >> >> Hey there >> >> >> >> I hope someone can help me with a script that can create a subfolder >> >> and >> >> copy a file from another folder into the newly created folder, but >> >> only >> >> if that folder and file doesn't exist. >> >> >> >> More specific, I have all our user home folders in 5 different >> >> subfolders, it looks something like this: >> >> >> >> d:\users\dep1\"accountname" >> >> \dep2\"accountname" >> >> >> >> And so on. The script needs to check if a folder called template >> >> exists >> >> in each "accountname" folder. If it doesn't exist it needs to create >> >> it >> >> and copy a file to it (d:\template\normal.dot) >> >> >> >> I have tried searching through the forum, and also on the internet, >> >> but >> >> with no luck. >> >> >> >> I hope someone here can help me. >> >> >> > >> > >> > if not exist d:\users\dep1\account ( >> > mkdir d:\users\dep1\account\template && >> > copy d:\template\normal.dot d:\users\dep1\account\template ) >> You could have mentioned that yours is a batch script rather than a >> vbscript. Still, for something like this that would be my tool of choice. >> Try putting the following ina .cmd file >> >> (set test=ECHO/) >> rem (set test=) >> for /d %%D in (d:\users\*.*) do call:dept "%%~D" >> pause & goto:Eof >> >> :dept >> for /d %%U in ("%%~1\*.*") do call:user "%%~U" >> goto:eof >> >> :user >> >> if not exist "%%~1\template" ( >> %test% md "%%~1\template" >> %test% copy d:\template\normal.dot "%%~1\template" >> ) >> goto:eof >> >> If you are happy with all of the md and copy commands that this displays, >> change this line: >> >> rem (set test=) >> >> to this >> >> (set test=) >> >> >> /Al >> >> >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| copy a file into all subfolders | PowerShell | |||
| Unzip a zip file which contains multiple subfolders using VBSCRIPT?! | VB Script | |||
| Batch file to execute files in subfolders | PowerShell | |||
| copy text files only from all subfolders within a folderto a another folder | VB Script | |||
| Propagating file permissions to all subfolders | Vista security | |||