Sign in to follow this  
Followers 0
Jac

Date function

12 posts in this topic

Hi im trying to delete all file in a folder that are older than 6 months. What is the easiest way you guy use for that ?

Thanks for helping me

Share this post


Link to post
Share on other sites



Look in the help file for _FileListToArray(), FileGetTime() and FileDelete()


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Hi im trying to delete all file in a folder that are older than 6 months. What is the easiest way you guy use for that ?

Thanks for helping me

Ok thanks. Do you know if it's possible with the function _NowCalc to return me the date in the same format on every computer. I would like to have it in format YYYY/MM/DD even if the date on the pc is in another format

Share this post


Link to post
Share on other sites

$a =  FileGetTime(@Windowsdir & "\Notepad.exe", 1); change this into your program path
$month=$a[1]
$thismon=@MON

$time = @MON - $month
if $time > 6 then
filedelete(@Windowsdir & "\Notepad.exe")
endif


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

$a =  FileGetTime(@Windowsdir & "\Notepad.exe", 1); change this into your program path
 $month=$a[1]
 $thismon=@MON
 
 $time = @MON - $month
 if $time > 6 then
 filedelete(@Windowsdir & "\Notepad.exe")
 endif
This is wrong, unless you want a lot of important things to be deleted. You must use DateDiff.

Share this post


Link to post
Share on other sites

$a =  FileGetTime(@Windowsdir & "\Notepad.exe", 1); change this into your program path
$month=$a[1]
$thismon=@MON

$time = @MON - $month
if $time > 6 then
filedelete(@Windowsdir & "\Notepad.exe")
endif
Here is my problem guys

$DateFile= FileGetTime($FileName,0)

$yyyymmdd = $DateFile[1] & "/" & $DateFile[2] & "/" & $DateFile[0]

$TimeFileExist = _DateDiff ( 'D', $yyyymmdd,StringLeft(_NowCalc(),10))

On a pc the StringLeft(_NowCalc(),10) return me 3/20/2008

So i can't compare it ?

What can i do ?

Thanks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This is wrong, unless you want a lot of important things to be deleted. You must use DateDiff.

his question is too informaless, this just show him the way it should be (at least a clue) ... also i gave a comment for changing the file path and anyone will be smart enough to change it, Edited by d4rk

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

Here is my problem guys

$DateFile= FileGetTime($FileName,0)

$yyyymmdd = $DateFile[1] & "/" & $DateFile[2] & "/" & $DateFile[0]

$TimeFileExist = _DateDiff ( 'D', $yyyymmdd,StringLeft(_NowCalc(),10))

On a pc the StringLeft(_NowCalc(),10) return me 3/20/2008

So i can't compare it ?

What can i do ?

Thanks

You aren't formatting your $yyyymmdd variable correctly.

$yyyymmdd = StringFormat("%s/%s/%s %s:%s:%s", $DateFile[0],$DateFile[1],$DateFile[2],$DateFile[3],$DateFile[4],$DateFile[5])

Also just leave _NowCalc as it is:

$TimeFileExist = _DateDiff ( 'D', $yyyymmdd,_NowCalc())

Share this post


Link to post
Share on other sites

Here is my problem guys

$DateFile= FileGetTime($FileName,0)

$yyyymmdd = $DateFile[1] & "/" & $DateFile[2] & "/" & $DateFile[0]

$TimeFileExist = _DateDiff ( 'D', $yyyymmdd,StringLeft(_NowCalc(),10))

On a pc the StringLeft(_NowCalc(),10) return me 3/20/2008

So i can't compare it ?

What can i do ?

Thanks

$DateFile[1] = month

$DateFile[2] = day

so why don't you turn something like this : $yyyymmdd = $DateFile[2] & "/" & $DateFile[1] & "/" & $DateFile[0]

don't know if i have understand clearly your question


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

his question is too informaless, this just show him the way it should be (at least a clue) ... also i gave a comment for changing the file path and anyone will be smart enough to change it, and i don't think if DateDiff work better then FileGetTime

You CANNOT perform math on dates in AutoIt using the standard operators, this is not PHP.

Share this post


Link to post
Share on other sites

You CANNOT perform math on dates in AutoIt using the standard operators, this is not PHP.

haha, got it :) next time i'll check in autoIT before showing some solution, sorry guy

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

You aren't formatting your $yyyymmdd variable correctly.

$yyyymmdd = StringFormat("%s/%s/%s %s:%s:%s", $DateFile[0],$DateFile[1],$DateFile[2],$DateFile[3],$DateFile[4],$DateFile[5])

Also just leave _NowCalc as it is:

$TimeFileExist = _DateDiff ( 'D', $yyyymmdd,_NowCalc())

Thanks you were right it working perfectly now !

Here is my code if somebody is interesting

; Script Start - Add your code below here

#Include <Date.au3>

$FileOlderThan = IniRead(@ScriptDir & "\Path.ini","FileOlderThan","Days","NotFound")

IF $FileOlderThan = "NotFound" Then

MsgBox(0,"Erreur","Vous devez inscrire le nombre de jour dans le fichier ini. Fin du programme")

Exit

EndIf

$Section = IniReadSection(@ScriptDir & "\Path.ini","Path")

For $i = 1 To $Section[0][0]

IF FileExists($Section[$i][1]) Then ScanFolder($Section[$i][1])

Next

Func ScanFolder($SourceFolder)

Local $Search

Local $File

Local $FileAttributes

Local $FullFilePath

$Search = FileFindFirstFile($SourceFolder & "\*.*")

While 1

If $Search = -1 Then

ExitLoop

EndIf

$File = FileFindNextFile($Search)

If @error Then ExitLoop

$FullFilePath = $SourceFolder & "\" & $File

$FileAttributes = FileGetAttrib($FullFilePath)

If StringInStr($FileAttributes,"D") Then

ScanFolder($FullFilePath)

Else

LogFile($FullFilePath)

EndIf

WEnd

FileClose($Search)

EndFunc

Func LogFile($FileName)

$DateFichier = FileGetTime($FileName,0)

$yyyymmdd = StringFormat("%s/%s/%s %s:%s:%s", $DateFichier[0],$DateFichier[1],$DateFichier[2],$DateFichier[3],$DateFichier[4],$DateFichier[5])

$NBJourFichierExiste = _DateDiff ( 'D', $yyyymmdd, _NowCalc() )

IF $NBJourFichierExiste > $FileOlderThan Then

$Resultat = FileDelete($FileName)

If $Resultat = 1 Then

FileWriteLine(@ScriptDir & "\FileListDelete.txt",_Now() & " : Le fichier " & $FileName & " a été supprimé")

EndIf

EndIf

EndFunc

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