Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Create subfolders and copy a file

Reply
 
Old 01-15-2009   #1 (permalink)
Janc


 
 

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 SpecsSystem Spec
Old 01-15-2009   #2 (permalink)
mayayana


 
 

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
a
Quote:

> file to it (d:\template\normal.dot)
>
> I have tried searching through the forum, and also on the internet, but
with
Quote:

> no luck.
>
> I hope someone here can help me.
>
> --
> /Jan

My System SpecsSystem Spec
Old 01-15-2009   #3 (permalink)
Luuk


 
 

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 SpecsSystem Spec
Old 01-15-2009   #4 (permalink)
Al Dunbar


 
 

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 )
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 SpecsSystem Spec
Old 01-20-2009   #5 (permalink)
JanC


 
 

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 SpecsSystem Spec
Old 01-20-2009   #6 (permalink)
Al Dunbar


 
 

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.
You are welcome. Sorry if my untested air code contained an error.

/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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46