Results 1 to 3 of 3

Thread: DIR & file functions

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    High Wycombe, United Kingdom
    Posts
    13

    DIR & file functions

    How can I check a directory to see whether it exists?
    If exists, how can I delete all files & sub folders under that directory?.
    Please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    dir command will tell you if it exists or not. I don't know any direct way of deleting every file an subdir in that dir but you could always go trough every single subdir having a procedure call itself to search trough subdirs and delete all file and remove the subdir. I have some related code if you want
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Wink

    Just a little DOS command, instead of using a recursive function to delete everything under a directory in VB (which works, but is way too much work), use the shell command with Deltree, as follows:
    Code:
    Call Shell("DELTREE /Y " & sDirectory, vbHide)
    It just sooo much easier! WHY doesn't VB or API include this command???

    BTW, make sure that the path that you specify does NOT include a trailing backslash, if it does then it will only delete everything under the specified directory and not the directory itself, for example:
    wrong: sDirectory = "C:\TEMP\TEST\"
    right: sDirectory = "C:\TEMP\TEST"
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

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