|
-
Aug 15th, 2000, 02:18 PM
#1
Thread Starter
Addicted Member
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\")
-
Aug 15th, 2000, 02:21 PM
#2
Fanatic Member
Is it possible to use the filesystemobject in a ASP?
I think you make more chance on a good answer in the asp/vbscript forum.
-
Aug 15th, 2000, 02:40 PM
#3
Monday Morning Lunatic
How about this?
Code:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.fileexists("c:\myfile.dat") then
...
end if
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 15th, 2000, 03:55 PM
#4
Hyperactive Member
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:
Code:
Dim fso
Set fso=CreateObject("scripting.FileSystemObject")
fso.CreateFolder "c:\myfolder"
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:
'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
Hope this helps.
-
Aug 15th, 2000, 04:14 PM
#5
Thread Starter
Addicted Member
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
|