PC Review


Reply
Thread Tools Rate Thread

Create folder in vbscript

 
 
Richard M.
Guest
Posts: n/a
 
      5th Nov 2003
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
 
 
 
 
LiquidJ
Guest
Posts: n/a
 
      5th Nov 2003
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." <(E-Mail Removed)> wrote in message
news:080601c3a3ae$0c552710$(E-Mail Removed)...
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
 
Richard M.
Guest
Posts: n/a
 
      5th Nov 2003
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." <(E-Mail Removed)> wrote

in message
>news:080601c3a3ae$0c552710$(E-Mail Removed)...
>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
 
LiquidJ
Guest
Posts: n/a
 
      5th Nov 2003
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." <(E-Mail Removed)> wrote in message
news:08d101c3a3b4$c95382c0$(E-Mail Removed)...
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." <(E-Mail Removed)> wrote

in message
>news:080601c3a3ae$0c552710$(E-Mail Removed)...
>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
 
Ricrard M.
Guest
Posts: n/a
 
      7th Nov 2003
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." <(E-Mail Removed)> wrote

in message
>news:08d101c3a3b4$c95382c0$(E-Mail Removed)...
>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." <(E-Mail Removed)> wrote

>in message
>>news:080601c3a3ae$0c552710$(E-Mail Removed)...
>>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
 
Dave
Guest
Posts: n/a
 
      10th Nov 2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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." <(E-Mail Removed)> wrote in message
> news:08d101c3a3b4$c95382c0$(E-Mail Removed)...
> 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." <(E-Mail Removed)> wrote

> in message
> >news:080601c3a3ae$0c552710$(E-Mail Removed)...
> >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
 
New Member
Join Date: Nov 2007
Posts: 2
 
      15th Nov 2007
'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
 
Reply With Quote
 
New Member
Join Date: Jan 2008
Posts: 1
 
      23rd Jan 2008
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
 
Reply With Quote
 
New Member
Join Date: Nov 2007
Posts: 2
 
      22nd Apr 2008
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; 22nd Apr 2008 at 11:10 PM..
 
Reply With Quote
 
New Member
Join Date: Jun 2008
Posts: 2
 
      17th Jun 2008
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.
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create ost with vbscript freddy Microsoft Outlook Installation 2 14th Jul 2011 11:07 AM
VBScript Create & Name a .pst sultanoswat@yahoo.com Microsoft Outlook VBA Programming 1 18th Sep 2006 06:54 PM
Create a DLL with VB.NET and use with VBScript =?Utf-8?B?S2V2aW4gQnVjaGFuYW4=?= Microsoft Dot NET 2 22nd Aug 2005 07:33 PM
create vbscript to create rule Noone Important Microsoft Outlook VBA Programming 1 8th Mar 2004 06:15 PM
Cannot create table using VBSCRIPT. Thomas L. Ickes Microsoft Access External Data 4 12th Nov 2003 10:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 PM.