Page 1 of 1

File Copy suggestion request

PostPosted: Tue Jan 13, 2015 10:01 am
by BRobinsonS
Using the code for menu option:
Code: Select all
FolderExists "[PubDir]Backup" "[BackupFolderExists]"
If "[BackupFolderExists]" "=" "False"
  CreateFolder "[PubDir]Backup"
Endif
FileCopy "[PubDir]AddressBook.mdb" "[PubDir]Backup\"


It works but I would like to attach perhaps an incremental number to the copied file so I have a series of backups.
Suggestions on how to do this?

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 10:27 am
by Gaev
Brian Robinson:

It works but I would like to attach perhaps an incremental number to the copied file so I have a series of backups.
Suggestions on how to do this?

You might consider, instead of an incremental number, appending a date as a suffix ... so today's backup would look like AddressBook 20150113.mdb.

And if you have reason to do more than one backup per day, you could choose to ...

- first erase the previous backup file

... or ...

- add a timestamp to the name e.g. AddressBook 20150113 122535.mdb

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 10:48 am
by BRobinsonS
My first inclination was date.
I guess that was my question "how do I append the date to the file name?"

What variable do I use or how do I get the 20150113 format so I get AddressBook 20150113.mdb ?

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 10:53 am
by HPW
You can cut it out of:

[DateShort] = The current date in Windows’ short format (10/22/07).

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 12:01 pm
by Neosoft Support
You could also do something like this:

FileCopy "[PubDir]AddressBook.mdb" "[PubDir]Backup\AddressBook[Year][MonthNum][DayNum].mdb"

[Year], [MonthNum] and [DayNum] are global variables.

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 12:18 pm
by Gaev
What Dave said ... plus you might allow for the single digit months and days with ...
Code: Select all
If "[MonthNum]" "<" "10"
    SetVar "[thisMonth]" "0[MonthNum]"
Else
    SetVar "[thisMonth]" "[MonthNum]"
EndIf
If "[DayNum]" "<" "10"
    SetVar "[thisDay]" "0[DayNum]"
Else
    SetVar "[thisDay]" "[DayNum]"
EndIf
...AlertBox "Year,Month,Day" "[Year][thisMonth][thisDay]"
FileCopy "[PubDir]AddressBook.mdb" "[PubDir]Backup\AddressBook[Year][thisMonth][thisDay].mdb"


Always using 2 digits for months and days makes it easier to view filenames (e.g. sorted in say Windows Explorer) in chronological order.

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 12:26 pm
by BRobinsonS
Once again thank you for the suggestions.

I like the last suggestion using [Year], [MonthNum] and [DayNum].
This allows me to build the appending string to add 0 if MonthNum or/and DayNum is less than 10 so I get 20150113 format and in year month day order.

As always Thank you for helping.

Re: File Copy suggestion request

PostPosted: Tue Jan 13, 2015 12:56 pm
by BRobinsonS
Thanks Gaev and Dave,
That basically how I do it now.
The code was so similar I wondered how you got my code. :lol: :?: