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 - creating complete file path

Reply
 
Old 09-12-2008   #1 (permalink)
Joachim Hofmann


 
 

creating complete file path

Hello,

The FileSystemObjects CreateFolder() can only create one folder at a time.
e.g.

CreateFolder(c:\temp)
CreateFolder(c:\temp\tempsub)
...


How can I create a given path "c:\temp\tempsub" at a time (or in a loop)?

Thank You

Joachim

My System SpecsSystem Spec
Old 09-12-2008   #2 (permalink)
ekkehard.horner


 
 

Re: creating complete file path

Joachim Hofmann schrieb:
Quote:

> Hello,
>
> The FileSystemObjects CreateFolder() can only create one folder at a time.
> e.g.
>
> CreateFolder(c:\temp)
> CreateFolder(c:\temp\tempsub)
> ..
>
>
> How can I create a given path "c:\temp\tempsub" at a time (or in a loop)?
>
> Thank You
>
> Joachim
see
http://www.visualbasicscript.com/fb.aspx?m=38936
My System SpecsSystem Spec
Old 09-12-2008   #3 (permalink)
James Whitlow


 
 

Re: creating complete file path

"Joachim Hofmann" <speicher@xxxxxx> wrote in message
news:%235vEfmLFJHA.2456@xxxxxx
Quote:

> Hello,
>
> The FileSystemObjects CreateFolder() can only create one folder at a time.
> e.g.
>
> CreateFolder(c:\temp)
> CreateFolder(c:\temp\tempsub)
I created me a function for this purpose a long time ago & just slot it
into any scripts I need this functionality in. Just use syntax like
'CreatePath "C:\One\Two\Three\Four", False'.

Function CreatePath(ByVal sPathName, ByVal bQuitOnFail)
Dim oFSO, sPath, sString, aPath
Set oFSO = CreateObject("Scripting.FileSystemObject")
aPath = Split(sPathName, "\")
On Error Resume Next
For Each sString in aPath
If Len(sString) Then
sPath = sPath & String(Abs(Len(sPath) > 0),"\") & sString
If Not oFSO.FolderExists(sPath) Then
oFSO.CreateFolder(sPath)
End If
End If
Next
On Error Goto 0
CreatePath = oFSO.FolderExists(sPathName)
If bQuitOnFail And Not CreatePath Then
MsgBox "Unable to create Folder:" & vbCrLf & sPathNAme, vbExclamation,
"Quitting!"
If Not TypeName(oIE) = "Object" Then oIE.Quit
WScript.Quit
End If
End Function


My System SpecsSystem Spec
Old 09-12-2008   #4 (permalink)
Todd Vargo


 
 

Re: creating complete file path

ekkehard.horner wrote:
Quote:

> Joachim Hofmann schrieb:
Quote:

> > Hello,
> >
> > The FileSystemObjects CreateFolder() can only create one folder at a
time.
Quote:
Quote:

> > e.g.
> >
> > CreateFolder(c:\temp)
> > CreateFolder(c:\temp\tempsub)
> > ..
> >
> >
> > How can I create a given path "c:\temp\tempsub" at a time (or in a
loop)?
Quote:
Quote:

> >
> > Thank You
> >
> > Joachim
>
> see
> http://www.visualbasicscript.com/fb.aspx?m=38936
Excellent subroutine, but mind the typo in the example calling line.
(Remove the close parenthesis preceding the ampersand.)

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Old 09-12-2008   #5 (permalink)
Al Dunbar


 
 

Re: creating complete file path


"Todd Vargo" <tlvargo@xxxxxx> wrote in message
news:O6%23lfUUFJHA.768@xxxxxx
Quote:

> ekkehard.horner wrote:
Quote:

>> Joachim Hofmann schrieb:
Quote:

>> > Hello,
>> >
>> > The FileSystemObjects CreateFolder() can only create one folder at a
> time.
Quote:
Quote:

>> > e.g.
>> >
>> > CreateFolder(c:\temp)
>> > CreateFolder(c:\temp\tempsub)
>> > ..
>> >
>> >
>> > How can I create a given path "c:\temp\tempsub" at a time (or in a
> loop)?
Quote:
Quote:

>> >
>> > Thank You
>> >
>> > Joachim
>>
>> see
>> http://www.visualbasicscript.com/fb.aspx?m=38936
>
> Excellent subroutine, but mind the typo in the example calling line.
> (Remove the close parenthesis preceding the ampersand.)
So you are saying to change this:

SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%") &
"\Program Files\Name1\Name2" )

to this:

SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%" &
"\Program Files\Name1\Name2" )

? Now we have more opening parens than closing ones - surely a syntax error
in either case.

I would propose this:

SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%" &
"\Program Files\Name1\Name2" ))

But then we could reduce the concatenation of two literal strings to one
literal string, i.e.:

SmartCreateFolder(WSHShell.ExpandEnvironmentStrings
("%SystemDrive%\Program Files\Name1\Name2" ))

And we could further reduce the redundant outer parens:

SmartCreateFolder WSHShell.ExpandEnvironmentStrings
("%SystemDrive%\Program Files\Name1\Name2" )

/Al


My System SpecsSystem Spec
Old 09-12-2008   #6 (permalink)
Al Dunbar


 
 

Re: creating complete file path


"Al Dunbar" <AlanDrub@xxxxxx> wrote in message
news:u3JmXmUFJHA.612@xxxxxx
Quote:

>
> "Todd Vargo" <tlvargo@xxxxxx> wrote in message
> news:O6%23lfUUFJHA.768@xxxxxx
Quote:

>> ekkehard.horner wrote:
Quote:

>>> Joachim Hofmann schrieb:
>>> > Hello,
>>> >
>>> > The FileSystemObjects CreateFolder() can only create one folder at a
>> time.
Quote:

>>> > e.g.
>>> >
>>> > CreateFolder(c:\temp)
>>> > CreateFolder(c:\temp\tempsub)
>>> > ..
>>> >
>>> >
>>> > How can I create a given path "c:\temp\tempsub" at a time (or in a
>> loop)?
Quote:

>>> >
>>> > Thank You
>>> >
>>> > Joachim
>>>
>>> see
>>> http://www.visualbasicscript.com/fb.aspx?m=38936
>>
>> Excellent subroutine, but mind the typo in the example calling line.
>> (Remove the close parenthesis preceding the ampersand.)
>
> So you are saying to change this:
>
> SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%") &
> "\Program Files\Name1\Name2" )
>
> to this:
>
> SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%" &
> "\Program Files\Name1\Name2" )
>
> ? Now we have more opening parens than closing ones - surely a syntax
> error in either case.
>
> I would propose this:
>
> SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%" &
> "\Program Files\Name1\Name2" ))
>
> But then we could reduce the concatenation of two literal strings to one
> literal string, i.e.:
>
> SmartCreateFolder(WSHShell.ExpandEnvironmentStrings
> ("%SystemDrive%\Program Files\Name1\Name2" ))
>
> And we could further reduce the redundant outer parens:
>
> SmartCreateFolder WSHShell.ExpandEnvironmentStrings
> ("%SystemDrive%\Program Files\Name1\Name2" )
Or even:

SmartCreateFolder
WSHShell.ExpandEnvironmentStrings("%ProgramFiles%\Name1\Name2" )

/Al


My System SpecsSystem Spec
Old 09-13-2008   #7 (permalink)
ekkehard.horner


 
 

Re: creating complete file path

Todd Vargo schrieb:
Quote:

> ekkehard.horner wrote:
Quote:

>> Joachim Hofmann schrieb:
[...]
Quote:
Quote:
Quote:

>>> How can I create a given path "c:\temp\tempsub" at a time (or in a loop)?
[...]
Quote:
>
> Excellent subroutine, but mind the typo in the example calling line.
> (Remove the close parenthesis preceding the ampersand.)
I can't rule out that the line was changed recently, but as it is now

SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%") & "\Program
Files\Name1\Name2" )

the close parenthesis preceding the ampersand is needed for the call of
..ExpandEnvironmentStrings.

According to the rule "no parameter list parentheses when callg a sub", the
*first* pair of () should be removed.

My System SpecsSystem Spec
Old 09-13-2008   #8 (permalink)
Al Dunbar


 
 

Re: creating complete file path


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:48cb53a8$0$3551$9b4e6d93@xxxxxx-online.net...
Quote:

> Todd Vargo schrieb:
Quote:

>> ekkehard.horner wrote:
Quote:

>>> Joachim Hofmann schrieb:
> [...]
Quote:
Quote:

>>>> How can I create a given path "c:\temp\tempsub" at a time (or in a
>>>> loop)?
> [...]
Quote:
>>
>> Excellent subroutine, but mind the typo in the example calling line.
>> (Remove the close parenthesis preceding the ampersand.)
>
> I can't rule out that the line was changed recently, but as it is now
>
> SmartCreateFolder(WSHShell.ExpandEnvironmentStrings ("%SystemDrive%") &
> "\Program Files\Name1\Name2" )
>
> the close parenthesis preceding the ampersand is needed for the call of
> .ExpandEnvironmentStrings.
oops, my bad, I was looking at it sideways and misconstruing the writer's
intent. That said, expandenvironmentstrings expands as batch does, and does
not need to be limited to one evn var per call.

/Al

Quote:

> According to the rule "no parameter list parentheses when callg a sub",
> the
> *first* pair of () should be removed.
>

My System SpecsSystem Spec
Old 09-13-2008   #9 (permalink)
Todd Vargo


 
 

Re: creating complete file path

Al Dunbar wrote:
Quote:
Quote:

> > And we could further reduce the redundant outer parens:
> >
> > SmartCreateFolder WSHShell.ExpandEnvironmentStrings
> > ("%SystemDrive%\Program Files\Name1\Name2" )
>
> Or even:
>
> SmartCreateFolder
> WSHShell.ExpandEnvironmentStrings("%ProgramFiles%\Name1\Name2" )
Good points but %SystemDrive% and %ProgramFiles% variables do not exist in
Windows 98, therefore I had only read the code without testing.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Extracting drive, path filebasename or extension from complete filename? VB Script
Command Prompt Auto Complete and path Completion Vista General
finding path to an .exe file Vista file management
rundll error while creating app path key Vista General
BUG? (Test-Path $path -IsValid) and empty $path PowerShell


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