Click to See Complete Forum and Search --> : FSO Help- Creating Subfolders


HerickPaiva
March 16th, 2001, 12:27 PM
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

vchapran
March 16th, 2001, 04:06 PM
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

Johnny101
March 16th, 2001, 04:33 PM
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