AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Script to move files older than 2 weeks into another folder

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
scriptmonkey



Joined: 19 May 2006
Posts: 112

PostPosted: Mon May 12, 2008 7:59 pm    Post subject: Script to move files older than 2 weeks into another folder Reply with quote

I am trying to create a script that moves files AND folders over 2 weeks old into a "old" folder.

Before I started moving things, I am trying to get the day values correct. I am having trouble with the script.

Code:

MainDir = C:\DOWNLOADS\*.*
Loop,%MainDir%
{
   var1= %A_Now%

   FileGetTime,var2,%A_LoopFileName%,C
   msgbox, todays date is %var1%
   EnvSub, var1,%var2%,days
   MsgBox, The file %A_LoopFileName% is %var1% days old
}
Return

_________________
Zak M.
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Mon May 12, 2008 10:43 pm    Post subject: Reply with quote

Search the forum for backup AND file.
Back to top
poo_noo



Joined: 08 Dec 2006
Posts: 137
Location: Sydney Australia

PostPosted: Mon May 12, 2008 11:20 pm    Post subject: Reply with quote

Here is some code that I found & adapted from the forum

Code:
      ; Read the source directory for stat log files and move files greater than log_file_age days old
      dir_source = %A_MyDocuments%\AutoHotkey\ahkstatsfile\*.log
      dir_backup = \\%mybackupServer%
      lastDate := A_Now
      lastDate += -%log_file_age%, Days
      Loop, %dir_source%
      {
         SplitPath A_LoopFileFullPath, name, dir, ext, name_no_ext, drive
         FileGetTime time, %A_LoopFileFullPath%
         if (time <= lastDate)
         FileMove %A_LoopFileFullPath%,%dir_backup%\%name%,1
         FileDelete %A_LoopFileFullPath%,%dir_backup%\%name%
         if ErrorLevel <0>
         GoTo initialballoon


The log_file_age variable is defined in an .INI

edit : oopppps I reread the post.... this only does files and not directories
_________________
Paul O
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group