Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

bat/cmd file help

  • 12-05-2005 12:51PM
    #1
    Registered Users, Registered Users 2 Posts: 902 ✭✭✭


    Howdy, need to write a bat/cmd file and need a little help. It has to do a simple function that after crawling through the web, seems not so simple.

    I have a folder on a server that contains sub-folders. Basically i need to write a script that runs as a scheduled task (every week/month, etc). And the script has to keep the sub-folders less than a month old, and delete everything else.

    In other words the folder on the server fills up on an irregular basis (could be 3 new sub folders a day, could be none) and we need to keep all folders for the past month and delete the rest...

    Messing about with dates through dos is worknig out to be a right b!tch...

    Any help appreciated


Comments

  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 95,993 Mod ✭✭✭✭Capt'n Midnight


    One way is to use the XCOPY /D /D:ddmmyy command - you copy all files less than a month old to a new folder and delete the rest and them copy them back

    pharsing the date to get a month and decrementing it is messy but can be done with FOR loops.


    http://www.robvanderwoude.com/index.html


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Would it help any to install Perl or PHP on the server and use a PHP/Perl script to do this?

    Perl is a whizz with this kind of thing.


  • Registered Users, Registered Users 2 Posts: 1,253 ✭✭✭gobby


    Could even try python scripting. I had to use python recently in college for various file operations and I found it quite nice. The website has a great help section too.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 95,993 Mod ✭✭✭✭Capt'n Midnight


    I'm not sure how consistant syntax has been over time in Python / Perl / PHP

    but the XCOPY command is all over the place with four main flavours :(
    * Dos/Dos Mode in 9x no /D
    * Win 9x command prompt /D
    * NT 3/4
    * 2K/XP (exclude , needing /Y to overwrite etc.)
    there are subtle differences too within the flavours...


  • Registered Users, Registered Users 2 Posts: 902 ✭✭✭thesteve


    Cheers for the replies lads, I'll give the XCOPY a go and let ye know how I get on... Never used perl before although getting training in it in a few weeks...


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 105 ✭✭nutzboutstuff


    why make it so complicated, install cygwin, and bash script it! a couple of greps an xargs and rm -rf and you're sorted, more details and i'll write it for you, and then you can cron it on the server for automatic execution


Advertisement