Sign in to follow this  
Followers 0
jben

Deleting folders older than 4 weeks

5 posts in this topic

One last quickie question.

I have folder setup like this

FOLDER200814

FOLDER200815

FOLDER200816

FOLDER200817

Is it possible that when FOLDER18 is created next week that folder 14 is removed...The numbers are just Week numbers..

C:\Output\"&@YEAR & _WeekNumberISO()

Thanks

Share this post


Link to post
Share on other sites



This should do it (add error checks)

#include <Date.au3>
$newfolder = "C:\Output\" & @YEAR & _WeekNumberISO()
$oldfolder = "C:\Output\" & @YEAR & _WeekNumberISO() - 4

If FileExists($oldfolder) Then DirRemove($oldfolder, 1)
DirCreate($newfolder)

MsgBox(0, "Weekly Folders", "Created: " & $newfolder & @CRLF & "Removed: " & $oldfolder)

One last quickie question.

What was the previous question :D

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This should do it (add error checks)

#include <Date.au3>
$newfolder = "C:\Output\" & @YEAR & _WeekNumberISO()
$oldfolder = "C:\Output\" & @YEAR & _WeekNumberISO() - 4

If FileExists($oldfolder) Then DirRemove($oldfolder, 1)
DirCreate($newfolder)

MsgBox(0, "Weekly Folders", "Created: " & $newfolder & @CRLF & "Removed: " & $oldfolder)

What was the previous question :D

Tut tut

Maybe the previous question was "What happens if the week nummber is less than 5?", though to be fair you did say to add error checks.

$oldweek = _WeekNumberISO() - 4
$oldyear = @Year
if $oldweek < 1 then
   $oldweek += 52
   $oldyear -= 1
endif
$oldfolder = "C:\Output\" & $oldyear & $oldweek
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Tut tut

Maybe the previous question was "What happens if the week nummber is less than 5?", though to be fair you did say to add error checks.

Accepted imaginary previous question, perhaps it should have been next question? :D

Don't you hate it when the original poster does not bother to check/respond/thank !

Share this post


Link to post
Share on other sites

hey daram...I do respond...

Sorry..Just had a really bad headache today and not feeling greay...Haven't had chance to try the code yet...Was going to try it out but had some problems with the code i'm going to use this with, therefore i tried fixing my code but started to get a severe headache so been taking a break.

Thanks everyone for your responses...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0