Jump to content

Has anyone script to copy a file as backup to same ...


Recommended Posts

I have 2 small 1k configuration files that keep getting overwritten. I suspect that the app I'm using as a portable app may not be portable or something, as it keeps deleting the files and goes back to blank. Since this app is otherwise perfect for my needs, if I could launch the app via an AI script then I could set it to copy the config files first then launch the app, then this problem would be averted. I've tested replacing different versions of the config files made at different times and know this aspect will work.

However, searching the forum didn't yield anything along the lines of what I need re the copying as it's rather complex. I also searched through the bat code I have and on the net (what I used a little bit before AI) and my tests have not been successful. The difficulty with trying to do this is that I need the filename to have a date _and_ time appended at the same time. Since I'll need to make 4 copies a day of these tiny config files, the appended time is important <g>.

Here's the situation, copying this file:

E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.cfg

with this "backup" script would result in:

E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.cfg - 2007.07.Wd., 10h51.cfg

if I applied the script right now.

Does anyone have code that does something like this that they can share, by any chance? When the code needs straightforward modifications, I seem to be able to handle that. Me and my being script-challenged makes life interesting.

Thank you! :)

Link to comment
Share on other sites

How about something simpler like first saving your config file as twc_backup.cfg. Then your launch script could just do something like this:

FileCopy("twc_backup.cfg","twc.cfg")

Run("TWC.EXE")

Hmmm, I don't know. On the surface this seems like it might have some merit but the difficulty is that I'd be left without "backup" copies. Also, if the config files still get knocked out, then I'd be copying blank, new config files anyway and I'd be right back where I started from.

Continuing to look at FileCopy. I don't see any "switches" as such as yet but I'm not done searching.

Also, forgot to mention that I tried XCOPY, too, but only managed to find syntax to make a copy to a separate folder. Not good enough.

Anyway, <sigh> code gives me heachaches <g>. Wish I was better at this sort of thing.

Thanks! :)

Link to comment
Share on other sites

$file = "E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.cfg"
$file2 = $file & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "hr" & @MIN & ".cfg"
FileCopy($file, $file2)oÝ÷ Ûú®¢×jr!j÷²¢êÛ­¨§Ùhwß}ÈÁ«"Ø^']궼¢Úµø¥zÆ j)â׬¥êÚ¶*'§ʫë,j¦­çhªÞ~·¬8^nV¬µçi®+jgbv+Z¨§jwl¢g­)àªizw¶ayéí®'¬¶­#]§^ßymi°ý½æ¥²¦j)^vØ^jëa¢º¶©®+jk(^~éeÊØ^­íý±§âÄwöÇëyì­ëa¢è!jwbµÚ±«)éÝØèní­§$x-g¢·lë-¶­²¶§G¦ÈZ¦§x-¢Ø^±ëmx,"fy§(º^¡÷!jx³öv+{vzkhmæëh©ÚëajÙmZØ^­íý³Z¶+,)'²Ö§¶¬Þ²gÞÝ÷jëh×6$file = "E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.cfg"
$file2 = $file & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & ".cfg"
FileCopy($file, $file2)


$file3 = "E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.ses"
$file4 = $file3 & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & ".ses"
FileCopy($file3, $file4)oÝ÷ Øý½éÞ½êÝ¢w[ajÖÞ~ÞnëhÇ«ÞÂäx¡×¢úèÚâj{(ëbë«zØb(ºÐr¦V²x0Ømí7éø¥{¬i¹^¶¶Ø^±ç(Ùbêr^v§v+p¢¹,·¶)ì¹Ç²È¨ýYçî®Ø^®jøjبÉZµêì¢ØZ¶Ø^jb²V®È^uënëH«Þj«²Ø¨kçm¡û«¶«r§ëayÊ)çgjgr§çmërÝ)Þ¡÷(uçë¢f®¶­sbb33c¶fÆS"Òb33c¶fÆRfײgV÷C²ÒgV÷C²fײT"fײgV÷C²âgV÷C²fײÔôâfײgV÷C²âgV÷C²fײÔDfײgV÷C²ÂgV÷C²fײõU"fײgV÷C¶gV÷C²fײÔâfײgV÷C²æ6frgV÷C°oÝ÷ ÚÚºÚ"µÍÌÍÙ[LH  ][ÝÞÔH   ][ÝÈ  [È ÌÍÙ[H    [È ][ÝÈH ][ÝÈ  [ÈQPT  [È ][ÝË][ÝÈ    [ÈSÓ  [È ][ÝË][ÝÈ    [ÈQVH  [È ][ÝË  ][ÝÈ  [ÈÕT  [È ][ÝÚ  ][ÝÈ  [ÈRS   [È ][ÝËÙÉ][Ý
to keep all the config files together and at the bottom of the folder, but then nothing happened at all, no copying occurred even. I thought that that might do the trick but no go. Is there a way to add "preface" text to the original line above?

Thanks everyone, as always, for such great help. :)

Link to comment
Share on other sites

The problem is that you were trying to add your file prefix to the complete path, so you ended up with something like this:

"zBKP- E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.cfg - 2007.07.Wd., 10h51.cfg"

which is of course an invalid file name. You have to separate out the filename from the directory path and then reassemble your new file name.

$file = "E:\APPS\TIMER-WORK\Time Worked Calculator\APP- Time Worked Calculator\twc.cfg"
$fileDir = Stringleft($file, StringInStr($file, "\", 0, -1) - 1)    ; Everything up to (but not including) the last backslash
$fileName = StringRight($file, StringLen($file) - StringInStr($file, "\", 0, -1))   ; What's left after the last backslash
$file2 = $fileDir & "\" & "zBKP- " & $fileName & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & ".cfg"
FileCopy($file, $file2)
BlueBearrOddly enough, this is what I do for fun.
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...