Results 1 to 5 of 5

Thread: ASP - FileSystemObject Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Question

    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\")
    Omar
    [email protected]
    http://omar.caribwalk.com
    To God Be The Glory

    I see Tech People ...

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    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.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    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.


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Smile Thanks

    Thanks Alot Guys
    Omar
    [email protected]
    http://omar.caribwalk.com
    To God Be The Glory

    I see Tech People ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width