Thread: Bat file help

    #1
  1. Blowing up trees with my mind.
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Feb 2005
    Location
    Neverland Ranch, minus the touching.
    Posts
    3,382
    Rep Power
    2567

    Bat file help


    Does anyone have a bat file that can delete all files in a directory (and its subdirectory, and THAT ones subdirectory, and so on) while leaving the directory structure intact? We have an ftp that we put data on for users to get, and its usually about 200-300 mb each, and i want to wipe it out weekly. They're supposed to delete it when they download it, but you know how that is...
  2. #2
  3. Not much of a contributor
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2006
    Location
    Hidden
    Posts
    1,012
    Rep Power
    1092
    Let me clear this a bit. The user downloads the folders and files from the ftp then you wanted to delete all files but leave the folders undeleted on the ftp.

    Am i right?
  4. #3
  5. Blowing up trees with my mind.
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Feb 2005
    Location
    Neverland Ranch, minus the touching.
    Posts
    3,382
    Rep Power
    2567
    Originally Posted by zynder
    Let me clear this a bit. The user downloads the folders and files from the ftp then you wanted to delete all files but leave the folders undeleted on the ftp.

    Am i right?
    Yes. And all files in the sub directories and directories in those, but leaving the structure intact.

    They are *supposed* to be cleaning their files out once they are downloaded (we let them store large files on our server for other cities and counties to download), but they never do...
  6. #4
  7. Not much of a contributor
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2006
    Location
    Hidden
    Posts
    1,012
    Rep Power
    1092
    I'm not good at bat files but this can be done effectively using a script or even much better an app jam packed with error handlers to ensure all files are deleted.

    But, one question though. Are the folders changing? or is it static? Coz if it's not changing you can delete them all then recreate the directory.
  8. #5
  9. manwich
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2003
    Location
    Canadanistan
    Posts
    578
    Rep Power
    385
    Just be careful if you choose to go with the delete + recreate, any custom permissions [aka ftp user access] are lost when the folder is deleted. The new folders will usually inherit permissions from their parent folder.
  10. #6
  11. Blowing up trees with my mind.
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Feb 2005
    Location
    Neverland Ranch, minus the touching.
    Posts
    3,382
    Rep Power
    2567
    Originally Posted by fubes2000
    Just be careful if you choose to go with the delete + recreate, any custom permissions [aka ftp user access] are lost when the folder is deleted. The new folders will usually inherit permissions from their parent folder.
    Yea they have permissions on them that will need to be maintained. They are all static directories.
  12. #7
  13. Blowing up trees with my mind.
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Feb 2005
    Location
    Neverland Ranch, minus the touching.
    Posts
    3,382
    Rep Power
    2567
    hmm, found it.

    del /f /s /q basedirectory.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    4
    Rep Power
    0
    If You Need a Complete batch Script then give this a go
    This Will delete all the files in C:\temp and subdirectories

    Code:
    @echo off
    setlocal
    pushd "c:\temp"
    for /f "tokens=*" %%a in ('dir /b /a-d /s *.*') do del /f /q "%%a"
    popd

IMN logo majestic logo threadwatch logo seochat tools logo