SuperFletch Posted December 18, 2012 Share Posted December 18, 2012 Hi, I expect this question has been asked a million times - so I apologise for this... I've searched but can't find what I'm looking for and I'm drawing a bit of a blank on where to start with it. I have a directory which automatically receives update files every now and then. I want to take the date of the newest file in that directory (DONE) then compare it to today's date. (Format DD/MM/YYYY) Using "If then Else" type logic I'll then work out whether the latest file is less than a week old and if it is then carry out some actions. Any ideas? I haven't got any code to post as I really don't know how to proceed. Thanks. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 18, 2012 Share Posted December 18, 2012 How are you getting the file date? You can get today's date using _Now(), _NowDate(), _NowCalc(), or _NowCalcDate() depending upon what format you want to get it in. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SuperFletch Posted December 18, 2012 Author Share Posted December 18, 2012 (edited) Using _RunDos to run the dir command with switches on it to order the results entries by date _RunDos('dir /O-D "C:MyDirectory" > dir.txt') Then I get the date using filereadline and stringleft as follows: $String = FileReadLine(@ScriptDir & 'dir.txt',6) $LatestDate = StringLeft($String,10) Todays date I was getting in the same format (DD/MM/YYYY) as follows; $TodaysDate = (@MDAY & "/" & @MON & "/" & @YEAR) Edited December 18, 2012 by SuperFletch Link to comment Share on other sites More sharing options...
BrewManNH Posted December 18, 2012 Share Posted December 18, 2012 If you use FileGetTime with the format parameter set to 1 you will get the file's date and time in a string value "1 = return a string YYYYMMDDHHMMSS" and you can pick that apart to get it in the format you need. You can then compare it to today's date using $TodaysDate = @YEAR & @MON & MDAY This way the two dates are in the same format and can be compared easily using an If statement. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SuperFletch Posted December 18, 2012 Author Share Posted December 18, 2012 (edited) Thanks for that - I've never used "FileGetTime" before. It's the If statement(s) I don't know where to start with. Edited December 18, 2012 by SuperFletch Link to comment Share on other sites More sharing options...
guinness Posted December 18, 2012 Share Posted December 18, 2012 Look at the help file about If statements. SuperFletch 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
BrewManNH Posted December 18, 2012 Share Posted December 18, 2012 Here's a short version you can adapt as needed. $FileDate = FileGetTime("somefile.txt", 0, 1); Returns the file's modified date in YYYYMMDDHHMMSS format $TodaysDate = @YEAR & @MON & @MDAY ; YYYYMMDD format If StringLeft($FileDate, 8) = $TodaysDate Then ; This compares the YYYYMMDD portion of $FileDate to $TodaysDate ; Do something here Endif If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
SuperFletch Posted December 24, 2012 Author Share Posted December 24, 2012 Look at the help file about If statements.I meant more the sort of conditions I'll be checking than how to structure them. Link to comment Share on other sites More sharing options...
SuperFletch Posted December 24, 2012 Author Share Posted December 24, 2012 Here's a short version you can adapt as needed. $FileDate = FileGetTime("somefile.txt", 0, 1); Returns the file's modified date in YYYYMMDDHHMMSS format $TodaysDate = @YEAR & @MON & @MDAY ; YYYYMMDD format If StringLeft($FileDate, 8) = $TodaysDate Then ; This compares the YYYYMMDD portion of $FileDate to $TodaysDate ; Do something here Endif Thanks - I was going to split the dates up but this seems more sensible. Link to comment Share on other sites More sharing options...
kylomas Posted December 24, 2012 Share Posted December 24, 2012 SuperFletch, This may be of interest. See comments in the code. ; ; list all files in the script directory with a modify date 1 year old or older ; #include <date.au3> local $files = FileFindFirstFile(@scriptdir & '\*.*'), $files, $fldate, $yy, $mm, $dd if $files = -1 then ConsoleWrite('No files found' & @LF) Exit endif while 1 $file = filefindnextfile($files) if @error then exitloop ; there's a bunch of ways to parse this date, this is just how I choose to do it this time $fldate = filegettime($file,0,1) $yy = stringleft($fldate,4) $fldate = stringtrimleft($fldate,4) $mm = stringleft($fldate,2) $fldate = stringtrimleft($fldate,2) $dd = stringleft($fldate,2) ; _datediff calcs date/time spans...see Help file if _datediff('D',$yy & '/' & $mm & '/' & $dd, _nowcalc()) > 365 then ConsoleWrite(stringformat('%-50s %50s',$file, ' Modily Date= ' & $yy & '/' & $mm & '/' & $dd) & @LF) EndIf wend kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted December 24, 2012 Share Posted December 24, 2012 This example returns the date in an array. ; ; list all files in the script directory with a modify date 1 year old or older ; #include <date.au3> local $files = FileFindFirstFile(@scriptdir & '\*.*'), $files, $fldate, $yy, $mm, $dd if $files = -1 then ConsoleWrite('No files found' & @LF) Exit endif while 1 $file = filefindnextfile($files) if @error then exitloop ; return the date in an array: ; [0] = year ; [1] = month ; [2] = day $fldate = filegettime($file,0) ; _datediff calcs date/time spans...see Help file if _datediff('D',$fldate[0] & '/' & $fldate[1] & '/' & $fldate[2], _nowcalc()) > 365 then ConsoleWrite(stringformat('%-50s %50s',$file, ' Modily Date= ' & $fldate[0] & '/' & $fldate[1] & '/' & $fldate[2]) & @LF) EndIf wend (...wasting time so I don't have to cook...) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
SuperFletch Posted January 8, 2013 Author Share Posted January 8, 2013 Thanks kylomas - this is the sort of thing I was looking for. Sorry for the slow reply... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now