Results 1 to 3 of 3

Thread: Automatically delete files

  1. #1
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Automatically delete files

    I am going to try and hit 2 similar birds with 1 stone in this thread.

    1) Our network printer has a scan to PDF function and the files are saved into the network folder G:\Scan Storage. People forget or accidentally hit the wrong button and the files never get removed. What I am looking to do is have files older than 14 days old get automatically deleted from the folder above. If it matters, only PDF's are stored in this folder.

    2) The next questions is similar to the one above. I would like to delete *.bak and plot.log files that are older than 30 days from the G: drive. There are hundreds of subdirectories and it needs to scan all of them.

    Is there some script that can automatically run these functions so I don't have to hit a button? If it matters, our server is using Win Server 2003. I don't know what kind of script is needed for my application. I don't care if the script is on our network or on my local (Win XP) machine.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Certainly possible. Basically, you will loop through every folder like this:
    open the main directory (G. Loop through every file/directory inside that:
    if file-- check if it's too old based on criteria (last 3 letters, date, etc), and delete if applicate
    if folder-- repeat this whole process by looping through that folder and its subfolders.
    When that subfolder is done, the main loop will continue through the rest of the folders in the main folder--
    and you'll have gone through every file on the drive.

    There are also some ways to set restrictions along the way (don't delete anything starting with an underscore, or skip folders named "save", etc.)

    Now, the real question is which language. If you happen to have PHP installed I could write this for you easily. I really should learn another language soon-- because right now that's about all I have to offer. You could probably do this with a batch file, if looping works properly-- I'm not sure how complex that can get, but I assume reasonable. (Or write a basic C++ program, etc.-- actually would be possible to compile a program from PHP like that, but you can probably find an easier way.)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2008
    Posts
    218
    Thanks
    7
    Thanked 19 Times in 19 Posts

    Default

    Are you allowed to use external program? If so look for a tool called LF and than use a cron job. An observation: i see you use spaces in your directory names. Delete doesn't like that very much
    Getting the names is simple dir /s (/b) *.ext, but also includes files you don't want to delete. I would try LF.

Bookmarks

Posting Permissions

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