Diana (Cda) Posted January 18, 2008 Share Posted January 18, 2008 (edited) I always seem to run into trouble the minute something gets a little complicated. I have a script that copies a file and then appends the current date and time to the end. This time, the need is much different and will save me so much time each week. It's a log file that needs to backed up weekly and it's called "twclog.txt". The backup copy should be renamed to have the start and end of week dates in the filename, so that for this week: Copy of "twclog.txt" would read in the end as "twclog.txt - 2008.01.14.Mn-2008.01.13.20.txt" Where Mon = Mn Tue = Tu Wed = Wd Thu = Th Fri = Fr Sat = Sa Sun = Sn I have modified the code I have to what I know how to do though it's not correct: $file = @ScriptDir & "\twclog.txt" $fileDir = Stringleft($file, StringInStr($file, "\", 0, -1) - 1) ; ALL up to (but not including) the last backslash $fileName = StringRight($file, StringLen($file) - StringInStr($file, "\", 0, -1)) ; what's left after last backslash ;$file2 = $file2 = $fileDir & "\" & $fileName & " - " & @YEAR & "." & @MON & "." & @MDAY & "-" & @YEAR & "." & @MON & "." & @MDAY & ".txt" FileCopy($file, $file2) This makes a copy of the twclog.txt file and names it today as this: twclog.txt - 2008.01.18-2008.01.18.txt Obviously the syntax needs to figure out how to actually rename the copy to this, this week: twclog.txt - 2008.01.14.Mn-2008.01.20.Sn.txt and next week, the same script no matter when I launched it, would produce this: twclog.txt - 2008.01.21.Mn-2008.01.27.Sn.txt etc. Can anyone help? This seems to be beyond my capabilities to produce as yet. Thank you, thank you, in advance. Edited January 27, 2008 by Diana (Cda) Link to comment Share on other sites More sharing options...
SpookMeister Posted January 18, 2008 Share Posted January 18, 2008 Look at FileGetTime() There is a way to query it for when it was created, and when it was last modified. Which I think should give you what you need. I'll try to throw an example together if I can spare a few mins. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
SpookMeister Posted January 18, 2008 Share Posted January 18, 2008 Oh, and you will probably need _DateToDayOfWeek() also... looks like I won't be able to work on it today after all. I'll try to check back later tonight if someone else doesn't help you throw something together first. -Spook [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Siao Posted January 19, 2008 Share Posted January 19, 2008 (edited) Here's a modified version of your script #Include <Date.au3> $file = @ScriptDir & "\twclog.txt" $fileDir = StringLeft($file, StringInStr($file, "\", 0, -1) - 1) ; ALL up to (but not including) the last backslash $file2 = $fileDir & "\twclog.txt - " & _GetWeeklyString() & ".txt" FileCopy($file, $file2) Func _GetWeeklyString() Local $iWeekStart = 0, $iWeekEnd = 6, $sDateStart, $sDateEnd Switch @WDAY Case 3 To 7 ;tue-sat $iWeekStart = 2-@WDAY $iWeekEnd = 8-@WDAY Case 1 ;sun $iWeekStart = -6 $iWeekEnd = 0 EndSwitch $sDateStart = StringReplace(_DateAdd('d', $iWeekStart, _NowCalcDate()), "/", ".") $sDateEnd = StringReplace(_DateAdd('d', $iWeekEnd, _NowCalcDate()), "/", ".") Return $sDateStart & '.Mn-' & $sDateEnd & '.Sn' EndFunc Edited January 19, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Diana (Cda) Posted January 27, 2008 Author Share Posted January 27, 2008 Here's a modified version of your script #Include <Date.au3> $file = @ScriptDir & "\twclog.txt" $fileDir = StringLeft($file, StringInStr($file, "\", 0, -1) - 1) ; ALL up to (but not including) the last backslash $file2 = $fileDir & "\twclog.txt - " & _GetWeeklyString() & ".txt" FileCopy($file, $file2) Func _GetWeeklyString() Local $iWeekStart = 0, $iWeekEnd = 6, $sDateStart, $sDateEnd Switch @WDAY Case 3 To 7 ;tue-sat $iWeekStart = 2-@WDAY $iWeekEnd = 8-@WDAY Case 1 ;sun $iWeekStart = -6 $iWeekEnd = 0 EndSwitch $sDateStart = StringReplace(_DateAdd('d', $iWeekStart, _NowCalcDate()), "/", ".") $sDateEnd = StringReplace(_DateAdd('d', $iWeekEnd, _NowCalcDate()), "/", ".") Return $sDateStart & '.Mn-' & $sDateEnd & '.Sn' EndFunc Thanks! 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