Re: How can I cause the datetime to be the name of the output file.....



Keith Thompson wrote:
"Merlin" <mrb7494@xxxxxxxxx> writes:

I realize that I'm new to the group, but I'm hoping that someone might
be able to help me out. What I'm doing is using the GNU 7zip command
line utility to make a backup on my desktop. Essentially, I'm running
an executable that will create a folder, and drop a zipped up copy of
my data to that folder. There doesn't seem to be a way to get 7zip to
automatically create a file where the filename.zip would be a date/time
stamp (something like 020206143260.zip.

What I'd like to be able to do is allow 7.zip to create the file with
some arbitrary name, and then use the rename() function and the time.h
library to somehow grab the current date/time from the computer and
rename the file with the filename being the date/time stamp.

Would time.h be the right library to use? If so, does anyone have any
suggestions as to how a solution might be implemented? Any thoughts
would be greatly appreciated.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>


main()
{

chdir("C:\\Documents and Settings\\All Users\\Desktop\\");
mkdir("Backup");
chdir("C:\\Program Files\\Backup Utility\\");
system("7za.exe a -tzip \"C:\\Documents and Settings\\All
Users\\Desktop\\Backup\\Backup.zip\" \"C:\\Program
Files\\Data\\*.*\"");
chdir("C:\\");

}


A lot of this (<unistd.h>, 7zip, anything having to do with
directories) isn't covered by standard C, and so is off-topic, but the
core of your question is topical.

Use "int main(void)" rather than "main()".

Check for, and handle, errors on your function calls.

Add a "return 0;" at the end of the program. You might also do a
"return EXIT_FAILURE;" or "exit(EXIT_FAILURE);" if you detect an error
(this requires <stdlib.h>).

Yes, <time.h> is the header (not library) that you want to use to deal
with timestamps. Call time() to get a raw timestamp, type time_t,
then use either gmtime() or localtime() to convert the time_t to a "
struct tm", then use strftime() to generate a string in whatever
format you like.

If you can specify the file name when you invoke the command itself,
you can build a command string using sprintf(); making sure the string
into which you write the formatted is long enough is left as an
exercise.

If your standard library supports it, I suggest the use of snprintf()
instead of sprintf() to take care of unforeseen situations.

<OT>
If you care about being able to understand the file names after you've
generated them, you might use a format other than 020206143260.zip,
perhaps something like 2006-02-02-143260.zip; using MMMM-DD-YY also

ITYM: YYYY-MM-DD Sort of a rotational error...

has the advantage that it sorts nicely in a directory listing.
</OT>

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.



Relevant Pages

  • Re: Time difference
    ... As John S has pointed out, a date/time data type is entirely inappropriate ... string, using the Format function, before you do any manipulation. ... Dim lSeconds As Long ...
    (microsoft.public.access.queries)
  • Re: Date Criteria Question
    ... field name) that was type Date/Time. ... If it is not a Date/Time type, ... "hierarchy" becomes a string sort, ... I have the tables and forms set to short date format which acepts dd mm yy ...
    (microsoft.public.access.queries)
  • Re: perl with mysql which takes a file as a input that contains the info to create the tables
    ... in the above text format u can find two tables one is Details> & the other ... strings, so you know that it will except a string. ... all you will need to do is shove the create table command in a single string ... Whatever command your string contains is then executed on your database so ...
    (perl.beginners)
  • Re: Help with query on a Date field for UK date style dd/mm/yyyy ???
    ... >format from the region settings in windows. ... regardless of the computer's date/time setting. ... >When I run the above query it says no records found. ... a string and then searching that string. ...
    (microsoft.public.access.queries)
  • Re: Date Criteria Question
    ... Yes the date type is date/time and yes I had named the field Date (which I ... "hierarchy" becomes a string sort, ... I have the tables and forms set to short date format which acepts dd mm yy ... tblTrainingSessions As T ...
    (microsoft.public.access.queries)