Hi,
I'me working on a web site that use ASP. My question
is, how can I check if a directory exist and if not
create it using FileSystemObject?.
Also : Is it possible to create multi-level directory.
example : MakeDirectory("images\gif\new\")
Printable View
Hi,
I'me working on a web site that use ASP. My question
is, how can I check if a directory exist and if not
create it using FileSystemObject?.
Also : Is it possible to create multi-level directory.
example : MakeDirectory("images\gif\new\")
Is it possible to use the filesystemobject in a ASP?:confused:
I think you make more chance on a good answer in the asp/vbscript forum.
How about this?
Code:Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.fileexists("c:\myfile.dat") then
...
end if
You check to see if a directory exists by doing the following:
Code:
Dim fso
Set fso=CreateObject("scripting.FileSystemObject")
If fso.FolderExists("c:\myFolder\")=true then
'your folder exists. Do something
Else
'your folder doesn't exists. Do something else
end if
Now for your second question. Creating a folder is easy. You just:
However, this command does not let you create multi-level directories. The best that you could do is quickly check to see if each directory in the path exists, and then create them as needed. I would assume something like this (though I didn't test it, so don't hold me to it).Code:
Dim fso
Set fso=CreateObject("scripting.FileSystemObject")
fso.CreateFolder "c:\myfolder"
Hope this helps.Code:
'All you need is a call to this function, and it should
'create all the directories for you.
Sub CreateDir(ByVal sNewDir)
Dim fso
Dim x
Set fso = CreateObject("scripting.FileSystemObject")
'Make sure the it ends in a "\" so that we know it is a
'directory.
If Right(sNewDir, 1) <> "\" Then
sNewDir = sNewDir & "\"
End If
x = InStr(1, sNewDir, "\")
Do Until x = Len(sNewDir)
If fso.FolderExists(Mid(sNewDir, 1, InStr(x + 1, sNewDir, "\"))) = False Then
fso.CreateFolder Mid(sNewDir, 1, InStr(x + 1, sNewDir, "\"))
End If
x = InStr(x + 1, sNewDir, "\")
Loop
MsgBox "finished"
End Sub
Thanks Alot Guys :) :)