Jump to content

Move files after certain date


Recommended Posts

Script masters, I need to be pointed in the right direction. I have been asked to come up with a script that will be run on a daily basis that will open a file or files on a server and remove (move to another folder) any files older than a certain date. Obviously, the cut off date will have to increment by one, and the script will need to run as a scheduled task. Any ideas?

Link to comment
Share on other sites

  • Moderators

Script masters, I need to be pointed in the right direction. I have been asked to come up with a script that will be run on a daily basis that will open a file or files on a server and remove (move to another folder) any files older than a certain date. Obviously, the cut off date will have to increment by one, and the script will need to run as a scheduled task. Any ideas?

Did you try the search... there was something on this I believe in the last 2 months (maybe 3).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

just playing here

#include <Date.au3>

$t =  FileGetTime(@Windowsdir & "\Notepad.exe", 1)
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$iDateCalc = _DateDiff( 'd',$yyyymd,_NowCalc())

If $iDateCalc > "60" Then
    MsgBox( 4096, "", "File deleted over 60 days old: " & $iDateCalc )
EndIf

8)

NEWHeader1.png

Link to comment
Share on other sites

I need to open a specific folder and all sub folders and files within. I then need to move (not delete) any files within the sub folder older than 7 days.

I experimented with the first portion of your script but I could not generate a list of file times.

#include <Date.au3>

$t =  FileGetTime(@Windowsdir & "\Notepad.exe", 1)
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$iDateCalc = _DateDiff( 'd',$yyyymd,_NowCalc())

What am I missing?

Link to comment
Share on other sites

I need to open a specific folder and all sub folders and files within. I then need to move (not delete) any files within the sub folder older than 7 days.

I experimented with the first portion of your script but I could not generate a list of file times.

#include <Date.au3>

$t =  FileGetTime(@Windowsdir & "\Notepad.exe", 1)
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$iDateCalc = _DateDiff( 'd',$yyyymd,_NowCalc())

What am I missing?

ok, i will look for the other thread because i KNOW that this exact thing was done fairly recently.

***edit***

blah. no time to really search right now. check this out for file searching

Edited by cameronsdad
Link to comment
Share on other sites

This portion of script provides the basis of what I am looking for. I can run it against a remote folder and it will generate a list of files based on the file extention I specify. The folder I will run it against in my production environment has three file extentions that I need sort and move to another folder based on their creation date. These extentions are none, .txt and .xls. I have been trying to insert the code suggested by Valuater, in it's current config I get the error: $yyyymd=$t^Error Subscript used with non array variable at this point in line four of the script.

How can I sort based on creation date and move the older files to another folder?

#include <Date.au3>

$t =  FileGetTime("E:" & "zip", 1)
$yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
$iDateCalc = _DateDiff( 'd',$yyyymd,_NowCalc())

$tosearch = "E:"
$output = FileOpen("c:\filelist.txt",2)
$start = TimerInit()
RecFileSearch($tosearch)
FileClose($output)
MsgBox(0,"done","it only took " & int(TimerDiff($start)/1000) & " seconds")
Func RecFileSearch($current)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
    Dim $file = FileFindNextFile($search)
    If @error Or StringLen($file)<1 Then ExitLoop
    FileWriteLine($output,$current & "\" & $file & "  zip  " & FileGetSize($file))
    If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file)
    WEnd
    FileClose($search)
EndFunc
Link to comment
Share on other sites

  • Developers

the error is because file E:zip doesn't exists so FileGetTime() ends in error that should be tested for.

here is a link to a script i posted in 2004 which you can modify for your use. it also does recursive search ..

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks, I was on your page earlier today looking at your findfiles.au3 script. I have adapted that for another use. The script you point me to will work, if I can modify it to archive the files rather then delete them. Also, you mention that it requires datenew.au3 include library which doesn't appear to be on your autoit page. Has that been incorporated into the latest version of AutoIt?

Link to comment
Share on other sites

  • Developers

Thanks, I was on your page earlier today looking at your findfiles.au3 script. I have adapted that for another use. The script you point me to will work, if I can modify it to archive the files rather then delete them. Also, you mention that it requires datenew.au3 include library which doesn't appear to be on your autoit page. Has that been incorporated into the latest version of AutoIt?

The text says datenew.au3, but when you look in the script you see I changed that a while ago to date.au3.

The datenew.au3 was at that time a propotype version of the current date.au3.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...