PC Review
Forums
Newsgroups
Windows 2000
Microsoft Windows 2000 Developer
Create folder in vbscript
Forums
Newsgroups
Windows 2000
Microsoft Windows 2000 Developer
Create folder in vbscript
![]() |
Create folder in vbscript |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 > > >. > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 > > >. > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 >> >> >>. >> > > >. > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
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 > > > > > >. > > > > |
|
|
|
#7 |
|
Junior Member
|
'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 |
|
|
|
|
|
#8 |
|
Junior Member
|
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 |
|
|
|
|
|
#9 |
|
Junior Member
|
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. |
|
|
|
|
|
#10 |
|
Junior Member
|
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.
|
|
|
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

