PC Review Forums Newsgroups Windows 2000 Microsoft Windows 2000 Developer Create folder in vbscript

Reply

Create folder in vbscript

 
Thread Tools Rate Thread
Old 05-11-2003, 03:04 PM   #1
Richard M.
Guest
 
Posts: n/a
Default Create folder in vbscript


Hi,

I´m using vbscript, and the problem is if i put inthe
script
fs.CreateFolder(""c:\test"), the folder was created.
If i put
fs.CreateFolder(""c:\Program Files\xpto\123\client\") i
had an error "path not found".

He only creates one directory in c:, but doesn´t create
the subdirectories.

Please help, it´s URGENT

Best Regards
  Reply With Quote
Old 05-11-2003, 03:44 PM   #2
LiquidJ
Guest
 
Posts: n/a
Default Re: Create folder in vbscript

Richard, you're going to have to check for the existance (or non-existance
as the case may be) of each subdirectory before calling CreateFolder(). In
your example, if any of the "Program Files", "xpto", or "123" directories do
not exist, you will not be able to create a "\Program Files\xpto\123\client"
directory using CreateFolder().


{L}



"Richard M." <anonymous@discussions.microsoft.com> wrote in message
news:080601c3a3ae$0c552710$a001280a@phx.gbl...
Hi,

I´m using vbscript, and the problem is if i put inthe
script
fs.CreateFolder(""c:\test"), the folder was created.
If i put
fs.CreateFolder(""c:\Program Files\xpto\123\client\") i
had an error "path not found".

He only creates one directory in c:, but doesn´t create
the subdirectories.

Please help, it´s URGENT

Best Regards


  Reply With Quote
Old 05-11-2003, 03:52 PM   #3
Richard M.
Guest
 
Posts: n/a
Default Re: Create folder in vbscript

The only folder that exists is "Program Files".
How can i create the other subdirectories.
Can you give me an example?

Thanks,

>-----Original Message-----
>Richard, you're going to have to check for the existance

(or non-existance
>as the case may be) of each subdirectory before calling

CreateFolder(). In
>your example, if any of the "Program Files", "xpto",

or "123" directories do
>not exist, you will not be able to create a "\Program

Files\xpto\123\client"
>directory using CreateFolder().
>
>
>{L}
>
>
>
>"Richard M." <anonymous@discussions.microsoft.com> wrote

in message
>news:080601c3a3ae$0c552710$a001280a@phx.gbl...
>Hi,
>
>I´m using vbscript, and the problem is if i put inthe
>script
>fs.CreateFolder(""c:\test"), the folder was created.
>If i put
>fs.CreateFolder(""c:\Program Files\xpto\123\client\") i
>had an error "path not found".
>
>He only creates one directory in c:, but doesn´t create
>the subdirectories.
>
>Please help, it´s URGENT
>
>Best Regards
>
>
>.
>

  Reply With Quote
Old 05-11-2003, 05:55 PM   #4
LiquidJ
Guest
 
Posts: n/a
Default Re: Create folder in vbscript

The same way you're trying to create the "client" directory...

Pseudocode:
If not exists (c:\Program Files)
CreateFolder(c:\Program Files)
end if

if not exists (c:\Program Files\xpto)
CreateFolder(c:\Program Files\xpto)
endif

if not exists (c:\program files\xpto\123)
CreateFolder(c:\program files\xpto\123)
endif

if not exists (c:\program files\xpto\123\client)
CreateFolder(c:\program files\xpto\123\client)
endif


Of course, the previous example can be cleaned up and optimized greatly, but
it shows the basic idea...


{L}



"Richard M." <anonymous@discussions.microsoft.com> wrote in message
news:08d101c3a3b4$c95382c0$a001280a@phx.gbl...
The only folder that exists is "Program Files".
How can i create the other subdirectories.
Can you give me an example?

Thanks,

>-----Original Message-----
>Richard, you're going to have to check for the existance

(or non-existance
>as the case may be) of each subdirectory before calling

CreateFolder(). In
>your example, if any of the "Program Files", "xpto",

or "123" directories do
>not exist, you will not be able to create a "\Program

Files\xpto\123\client"
>directory using CreateFolder().
>
>
>{L}
>
>
>
>"Richard M." <anonymous@discussions.microsoft.com> wrote

in message
>news:080601c3a3ae$0c552710$a001280a@phx.gbl...
>Hi,
>
>I´m using vbscript, and the problem is if i put inthe
>script
>fs.CreateFolder(""c:\test"), the folder was created.
>If i put
>fs.CreateFolder(""c:\Program Files\xpto\123\client\") i
>had an error "path not found".
>
>He only creates one directory in c:, but doesn´t create
>the subdirectories.
>
>Please help, it´s URGENT
>
>Best Regards
>
>
>.
>



  Reply With Quote
Old 07-11-2003, 10:50 AM   #5
Ricrard M.
Guest
 
Posts: n/a
Default Re: Create folder in vbscript

Thanks.
>-----Original Message-----
>The same way you're trying to create the "client"

directory...
>
>Pseudocode:
>If not exists (c:\Program Files)
> CreateFolder(c:\Program Files)
>end if
>
>if not exists (c:\Program Files\xpto)
> CreateFolder(c:\Program Files\xpto)
>endif
>
>if not exists (c:\program files\xpto\123)
> CreateFolder(c:\program files\xpto\123)
>endif
>
>if not exists (c:\program files\xpto\123\client)
> CreateFolder(c:\program files\xpto\123\client)
>endif
>
>
>Of course, the previous example can be cleaned up and

optimized greatly, but
>it shows the basic idea...
>
>
>{L}
>
>
>
>"Richard M." <anonymous@discussions.microsoft.com> wrote

in message
>news:08d101c3a3b4$c95382c0$a001280a@phx.gbl...
>The only folder that exists is "Program Files".
>How can i create the other subdirectories.
>Can you give me an example?
>
>Thanks,
>
>>-----Original Message-----
>>Richard, you're going to have to check for the existance

>(or non-existance
>>as the case may be) of each subdirectory before calling

>CreateFolder(). In
>>your example, if any of the "Program Files", "xpto",

>or "123" directories do
>>not exist, you will not be able to create a "\Program

>Files\xpto\123\client"
>>directory using CreateFolder().
>>
>>
>>{L}
>>
>>
>>
>>"Richard M." <anonymous@discussions.microsoft.com> wrote

>in message
>>news:080601c3a3ae$0c552710$a001280a@phx.gbl...
>>Hi,
>>
>>I´m using vbscript, and the problem is if i put inthe
>>script
>>fs.CreateFolder(""c:\test"), the folder was created.
>>If i put
>>fs.CreateFolder(""c:\Program Files\xpto\123\client\") i
>>had an error "path not found".
>>
>>He only creates one directory in c:, but doesn´t create
>>the subdirectories.
>>
>>Please help, it´s URGENT
>>
>>Best Regards
>>
>>
>>.
>>

>
>
>.
>

  Reply With Quote
Old 10-11-2003, 12:09 PM   #6
Dave
Guest
 
Posts: n/a
Default Re: Create folder in vbscript

Hi all,
heres a recursive proceedure I use to create the folder tree instead of
having it hardcoded.

hth,
Dave

'--------- CODE
Public objFSO

Sub Main()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call
GeneratePath("C:\test1\test2\test3\test4\test5\test6\test7\test8\test9")
End Sub

' ---------------------------------------------------------------------
'* @info Generate a folder tree from the path
'*
'* @param (String) Path
'* @return (Boolean) Folder Exists: Recursion continues (Y/N)
' ---------------------------------------------------------------------
Function GeneratePath(pFolderPath)
GeneratePath = False
If Not objFSO.FolderExists(pFolderPath) Then
If GeneratePath(objFSO.GetParentFolderName(pFolderPath)) Then
GeneratePath = True
Call objFSO.CreateFolder(pFolderPath)
End If
Else
GeneratePath = True
End If
End Function

Call Main
'------- END CODE





"LiquidJ" <replytogroup@boo.yah> wrote in message
news:e8LExX8oDHA.2456@TK2MSFTNGP09.phx.gbl...
> The same way you're trying to create the "client" directory...
>
> Pseudocode:
> If not exists (c:\Program Files)
> CreateFolder(c:\Program Files)
> end if
>
> if not exists (c:\Program Files\xpto)
> CreateFolder(c:\Program Files\xpto)
> endif
>
> if not exists (c:\program files\xpto\123)
> CreateFolder(c:\program files\xpto\123)
> endif
>
> if not exists (c:\program files\xpto\123\client)
> CreateFolder(c:\program files\xpto\123\client)
> endif
>
>
> Of course, the previous example can be cleaned up and optimized greatly,

but
> it shows the basic idea...
>
>
> {L}
>
>
>
> "Richard M." <anonymous@discussions.microsoft.com> wrote in message
> news:08d101c3a3b4$c95382c0$a001280a@phx.gbl...
> The only folder that exists is "Program Files".
> How can i create the other subdirectories.
> Can you give me an example?
>
> Thanks,
>
> >-----Original Message-----
> >Richard, you're going to have to check for the existance

> (or non-existance
> >as the case may be) of each subdirectory before calling

> CreateFolder(). In
> >your example, if any of the "Program Files", "xpto",

> or "123" directories do
> >not exist, you will not be able to create a "\Program

> Files\xpto\123\client"
> >directory using CreateFolder().
> >
> >
> >{L}
> >
> >
> >
> >"Richard M." <anonymous@discussions.microsoft.com> wrote

> in message
> >news:080601c3a3ae$0c552710$a001280a@phx.gbl...
> >Hi,
> >
> >I´m using vbscript, and the problem is if i put inthe
> >script
> >fs.CreateFolder(""c:\test"), the folder was created.
> >If i put
> >fs.CreateFolder(""c:\Program Files\xpto\123\client\") i
> >had an error "path not found".
> >
> >He only creates one directory in c:, but doesn´t create
> >the subdirectories.
> >
> >Please help, it´s URGENT
> >
> >Best Regards
> >
> >
> >.
> >

>
>



  Reply With Quote
Old 15-11-2007, 03:40 PM   #7
LudvikJerabek
Junior Member
 
Join Date: Nov 2007
Posts: 2
Trader Rating: (0)
Default

'This is the easiest way to do this recursive function to create the path structure
Sub CreateFolder( strPath )
Dim objFSO ' Could be made global..
Set objFSO = CreateObject("Scripting.FileSystemObject") 'Could be set global...
If Not objFSO.FolderExists( objFSO.GetParentFolderName(strPath) ) then Call CreateFolder( objFSO.GetParentFolderName(strPath) )
objFSO.CreateFolder( strPath )
End Sub
LudvikJerabek is offline   Reply With Quote
Old 23-01-2008, 06:14 AM   #8
sraju_india
Junior Member
 
Join Date: Jan 2008
Posts: 1
Trader Rating: (0)
Default Creating the folder with date and month inside a directory

Hi Liqud

I am trying to create a folder with name as "<date> space <Month name>, for ex: 23 Jan'08

for doing this i am trying to create a vbs script and i am failing again and again

i have tried getting the script from the net, and i am trying to modify that and create a new one for my use to do my task

and i am new to this vbs scripts, having some idea ..how to do and how to execute...but not having enough exp. in writing that

please help me regarding this..how to create that ?

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
set T = %time%
Const TargetDir = "D:testing'T'"
objFSO.CreateFolder(TargetDir)

i am testing with this one

thanks
raj
sraju_india is offline   Reply With Quote
Old 22-04-2008, 11:08 PM   #9
LudvikJerabek
Junior Member
 
Join Date: Nov 2007
Posts: 2
Trader Rating: (0)
Default

There was a potential bug in the original recursive create folder post... it is corrected below.

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

'Recursive folder create, will create directories and Sub
Sub CreateFolder( strPath )
On Error Resume Next
If strPath <> "" Then 'Fixes endless recursion in some instances when at lowest directory
If Not objFSO.FolderExists( objFSO.GetParentFolderName(strPath) ) then Call CreateFolder( objFSO.GetParentFolderName(strPath) )
objFSO.CreateFolder( strPath )
End If
End Sub

Last edited by LudvikJerabek : 22-04-2008 at 11:10 PM.
LudvikJerabek is offline   Reply With Quote
Old 17-06-2008, 11:21 AM   #10
AndyOng
Junior Member
 
Join Date: Jun 2008
Posts: 1
Trader Rating: (0)
Default

Script looks good guys. I've been trying to put together a script to create folders, and set folder permissions using vbscript that has been added as a custom action to run in an msi. Was tearing my hair out as the .vbs script would create the folder when run on its own, but when run from within the msi it didn't do the create. Figured out in the end that the createObject for the filesystemobject was using wscript, and wscript just doesn't seem to work when run from within an msi. All good now and gonna look at incorporating your recursive folder creates.
AndyOng is offline   Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off