|
-
March 16th, 2001, 01:27 PM
#1
FSO Help- Creating Subfolders
Hi ,
How do I create folder/subfolders using FSO?? I can create something like c:\images\, but I want to be able to create subfolders under this. I need to have a button that picks up a value typed in a texbox ( images\gifs\) and create these 2 folders
Please Help.
Herick
-
March 16th, 2001, 05:06 PM
#2
Re: FSO Help- Creating Subfolders
Don't remember how to use FSO for your task, but it's easy with API.
private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (byval lpPathName as string, lpSecurityAttributes as SECURITY_ATTRIBUTES) as Long
private Type SECURITY_ATTRIBUTES
nLength as Long
lpSecurityDescriptor as Long
bInheritHandle as Long
End Type
'then
Dim udtSecAttr as SECURITY_ATTRIBUTES
Call CreateDirectory("C:\Testing", udtSecAttr)
You need to validate value in Text box, then separate entire entry on folders names with let's say InStr function and then in loop create all folders and subfolders using CreateDirectory API.
HTH
Vlad
-
March 16th, 2001, 05:33 PM
#3
Re: FSO Help- Creating Subfolders
Here's the FSO way of doing the same as below - iterating through the full path and creating directories as needed:
private Sub Form_DblClick()
Dim FSO as Scripting.FileSystemObject
Dim sFileName() as string
Dim sFolder as string
Dim i as Integer
sFileName = Split(Text1.Text, "\")
set FSO = new Scripting.FileSystemObject
for i = LBound(sFileName) to UBound(sFileName)
If i = 0 then
sFolder = sFileName(0) & "\" & sFileName(1)
i = 1
else
sFolder = sFolder & "\" & sFileName(i)
End If
If FSO.FolderExists(sFolder) then
'do nothing it's already there
else
Call FSO.CreateFolder(sFolder)
End If
next i
set FSO = nothing
End Sub
for example, place a text box on a form, place the above code in the form_dblclick() event. runthe application and enter "c:\myfolder\subfolder\this\is\cool" - double click the form and directories are created. then add on to the above string - "\and\i use\the\fso" - double the form again and walla -more directories!
hope this helps,
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|