View Full Version : Saving A File With the Date attached
Travis
December 5th 03, 11:01 PM
I was wondering if there is a way to automate date
insertion on filenames for programs that run scheduled.
For example what if I have audit software running and
everynight it saves a text file to the hard drive. Since
it has the same name in the save as area then it
continuously overwrites the old one. What if I want to
keep the old ones though by date?
Something that would give me the below.
c:\audit\21Sep03
Thank You in advance.
Rob Schneider
December 5th 03, 11:01 PM
Travis wrote:
> I was wondering if there is a way to automate date
> insertion on filenames for programs that run scheduled.
>
> For example what if I have audit software running and
> everynight it saves a text file to the hard drive. Since
> it has the same name in the save as area then it
> continuously overwrites the old one. What if I want to
> keep the old ones though by date?
>
> Something that would give me the below.
>
> c:\audit\21Sep03
>
> Thank You in advance.
The easiest way would be to check that your audit software doesn't have
some setting in it itself to control the name of the file so that it
doesn't automatically over-write itself. Seems like that would be
reasonable to expect such a thing in audit software.
The next easiest way would be to write a small program that would be
scheduled to run after the audit program to copy the created file into a
new file which, say, incorporates the date in it's file name, e.g.
21SEP03.TEXT or to enable correct file sorting in Explorer, make it
030921.TXT. This program could be written as BAT file using normal
commands, or you could use a progamming langauge like Visual Basic,
Perl, or Python. While this is very simple to do, it does require a bit
of knowledge and experience in programming.
Travis
December 5th 03, 11:01 PM
>-----Original Message-----
>Travis wrote:
>
>> I was wondering if there is a way to automate date
>> insertion on filenames for programs that run scheduled.
>>
>> For example what if I have audit software running and
>> everynight it saves a text file to the hard drive.
Since
>> it has the same name in the save as area then it
>> continuously overwrites the old one. What if I want
to
>> keep the old ones though by date?
>>
>> Something that would give me the below.
>>
>> c:\audit\21Sep03
>>
>> Thank You in advance.
>
>The easiest way would be to check that your audit
software doesn't have
>some setting in it itself to control the name of the
file so that it
>doesn't automatically over-write itself. Seems like that
would be
>reasonable to expect such a thing in audit software.
>
>The next easiest way would be to write a small program
that would be
>scheduled to run after the audit program to copy the
created file into a
>new file which, say, incorporates the date in it's file
name, e.g.
>21SEP03.TEXT or to enable correct file sorting in
Explorer, make it
>030921.TXT. This program could be written as BAT file
using normal
>commands, or you could use a progamming langauge like
Visual Basic,
>Perl, or Python. While this is very simple to do, it
does require a bit
>of knowledge and experience in programming.
>
>.
Precisely this is not pertaining to auditing software,
but used as an example. I had a feeling I might have to
write something to accomplish what I needed. I was
really hoping that Microsoft had provided variable
support when using Save as: to add information such as
the date to the end of the filename. Thanks for your
help.
David Candy
December 5th 03, 11:01 PM
cmd /c echo. |time>myfile.txt
for /f "tokens=3D5" %A In (myfile.txt) Do Copy %1 %A.txt
Note. If you use : as a hour seperator it won't work. So yopu'll need to =
go through it again with for /f to extract the time with out a colon.
See for /?
akso note in a batch file %A is %%A, %B is %%B, ,,, . %n is %%n.
EG this batch file copies any file dropped on it with the time as the =
name (to the hundreds of a second), substituting dashes for colons
echo.|time>c:\myfile.txt
for /f "tokens=3D5,6,7,8 delims=3D: " %%A In (c:\myfile.txt) Do copy %1 =
%%A-%%B-%%C-%%D.txt
If you want to get fancy with paths the For command can also pull out =
parts of file names. See For /?. But I'd just hardcode the paths.
--=20
David Candy
http://www.mvps.org/serenitymacros/
http://www.simtel.com/pub/pd/18669.html
"Travis" > wrote in message =
...
> I was wondering if there is a way to automate date=20
> insertion on filenames for programs that run scheduled.
>=20
> For example what if I have audit software running and=20
> everynight it saves a text file to the hard drive. Since=20
> it has the same name in the save as area then it=20
> continuously overwrites the old one. What if I want to=20
> keep the old ones though by date?
>=20
> Something that would give me the below.
>=20
> c:\audit\21Sep03
>=20
> Thank You in advance.
Rob Schneider
December 5th 03, 11:01 PM
Travis wrote:
>>-----Original Message-----
>>Travis wrote:
>>
>>
>>>I was wondering if there is a way to automate date
>>>insertion on filenames for programs that run scheduled.
>>>
>>>For example what if I have audit software running and
>>>everynight it saves a text file to the hard drive.
>
> Since
>
>>>it has the same name in the save as area then it
>>>continuously overwrites the old one. What if I want
>
> to
>
>>>keep the old ones though by date?
>>>
>>>Something that would give me the below.
>>>
>>>c:\audit\21Sep03
>>>
>>>Thank You in advance.
>>
>>The easiest way would be to check that your audit
>
> software doesn't have
>
>>some setting in it itself to control the name of the
>
> file so that it
>
>>doesn't automatically over-write itself. Seems like that
>
> would be
>
>>reasonable to expect such a thing in audit software.
>>
>>The next easiest way would be to write a small program
>
> that would be
>
>>scheduled to run after the audit program to copy the
>
> created file into a
>
>>new file which, say, incorporates the date in it's file
>
> name, e.g.
>
>>21SEP03.TEXT or to enable correct file sorting in
>
> Explorer, make it
>
>>030921.TXT. This program could be written as BAT file
>
> using normal
>
>>commands, or you could use a progamming langauge like
>
> Visual Basic,
>
>>Perl, or Python. While this is very simple to do, it
>
> does require a bit
>
>>of knowledge and experience in programming.
>>
>>.
>
>
> Precisely this is not pertaining to auditing software,
> but used as an example. I had a feeling I might have to
> write something to accomplish what I needed. I was
> really hoping that Microsoft had provided variable
> support when using Save as: to add information such as
> the date to the end of the filename. Thanks for your
> help.
See David Candy's reply where he provides you some code.
Microsoft *does* provide the capability to create a filename by date (or
anything else) and then save the file. This is why what David suggests
works. And even better, if you don't like David's way, there there are
a lot of other ways to accomplish this, all enabled by what Microsoft
provides in XP.
David Candy
December 5th 03, 11:01 PM
XP can do it at the command prompt but not in a windows programs. =20
There is also %time% that is in NT based systems (not 9x but then =
neither is those for /f commands). But File - Save As only returns what =
you type or select to the program, and most programs don't expect =
environtmental variables, so unless the program expands then it will be =
treated as text. Note this is the program not windows that decides what =
to do.
--=20
David Candy
http://www.mvps.org/serenitymacros/
http://www.simtel.com/pub/pd/18669.html
"Rob Schneider" et> =
wrote in message ...
> Travis wrote:
>=20
> >>-----Original Message-----
> >>Travis wrote:
> >>
> >>
> >>>I was wondering if there is a way to automate date=20
> >>>insertion on filenames for programs that run scheduled.
> >>>
> >>>For example what if I have audit software running and=20
> >>>everynight it saves a text file to the hard drive. =20
> >=20
> > Since=20
> >=20
> >>>it has the same name in the save as area then it=20
> >>>continuously overwrites the old one. What if I want=20
> >=20
> > to=20
> >=20
> >>>keep the old ones though by date?
> >>>
> >>>Something that would give me the below.
> >>>
> >>>c:\audit\21Sep03
> >>>
> >>>Thank You in advance.
> >>
> >>The easiest way would be to check that your audit=20
> >=20
> > software doesn't have=20
> >=20
> >>some setting in it itself to control the name of the=20
> >=20
> > file so that it=20
> >=20
> >>doesn't automatically over-write itself. Seems like that=20
> >=20
> > would be=20
> >=20
> >>reasonable to expect such a thing in audit software.
> >>
> >>The next easiest way would be to write a small program=20
> >=20
> > that would be=20
> >=20
> >>scheduled to run after the audit program to copy the=20
> >=20
> > created file into a=20
> >=20
> >>new file which, say, incorporates the date in it's file=20
> >=20
> > name, e.g.=20
> >=20
> >>21SEP03.TEXT or to enable correct file sorting in=20
> >=20
> > Explorer, make it=20
> >=20
> >>030921.TXT. This program could be written as BAT file=20
> >=20
> > using normal=20
> >=20
> >>commands, or you could use a progamming langauge like=20
> >=20
> > Visual Basic,=20
> >=20
> >>Perl, or Python. While this is very simple to do, it=20
> >=20
> > does require a bit=20
> >=20
> >>of knowledge and experience in programming.
> >>
> >>.
> >=20
> >=20
> > Precisely this is not pertaining to auditing software,=20
> > but used as an example. I had a feeling I might have to=20
> > write something to accomplish what I needed. I was=20
> > really hoping that Microsoft had provided variable=20
> > support when using Save as: to add information such as=20
> > the date to the end of the filename. Thanks for your=20
> > help.
>=20
> See David Candy's reply where he provides you some code.
>=20
> Microsoft *does* provide the capability to create a filename by date =
(or=20
> anything else) and then save the file. This is why what David =
suggests=20
> works. And even better, if you don't like David's way, there there =
are=20
> a lot of other ways to accomplish this, all enabled by what Microsoft=20
> provides in XP.
>=20
>=20
Rob Schneider
December 5th 03, 11:01 PM
David Candy wrote:
> XP can do it at the command prompt but not in a windows programs.
>
> There is also %time% that is in NT based systems (not 9x but then neither is those for /f commands). But File - Save As only returns what you type or select to the program, and most programs don't expect environtmental variables, so unless the program ex
pands then it will be treated as text. Note this is the program not windows that decides what to do.
Of course it can.
Write a Windows program (by that I mean VB, Word VBA, C, C++, ... pretty
much reasonable programming langauge or macro language attached to an
application) which appends the date in string format to a file name,
then save it. Not all windows programs have built in macro programming
langagues, nor do all of them respond to COM instructions, so you have
pick the right architecture/design.
The Operating System (Call it Windows, NT, XP, or whatever) exposes to
the program the date information (stored on the computer's date hardware
and software), and it exposes to the program the abilty to write files
to storage devides (disks, floppies, etc.)
David Candy
December 5th 03, 11:02 PM
Expansion happens automatically with file associations. If explorer see =
a reg_expand registry data type it calls ExpandEnvironmentStrings. But =
windows is not in control in a program, the program is, So entering =
%time% in a File Save As dialog depend entirely on the program what =
happens. Save As just tells the programs the user typed %time% (which is =
a legal file name) and if the program doesn't ca;ll an expansoion =
functions then it will save with that name.
<quote>
I was=20
really hoping that Microsoft had provided variable=20
support when using Save as: to add information such as=20
the date to the end of the filename.=20
</quote>
--=20
David Candy
http://www.mvps.org/serenitymacros/
http://www.simtel.com/pub/pd/18669.html
"Rob Schneider" et> =
wrote in message ...
> David Candy wrote:
>=20
> > XP can do it at the command prompt but not in a windows programs. =20
> >=20
> > There is also %time% that is in NT based systems (not 9x but then =
neither is those for /f commands). But File - Save As only returns what =
you type or select to the program, and most programs don't expect =
environtmental variables, so unless the program expands then it will be =
treated as text. Note this is the program not windows that decides what =
to do.
>=20
> Of course it can.
>=20
> Write a Windows program (by that I mean VB, Word VBA, C, C++, ... =
pretty=20
> much reasonable programming langauge or macro language attached to an=20
> application) which appends the date in string format to a file name,=20
> then save it. Not all windows programs have built in macro =
programming=20
> langagues, nor do all of them respond to COM instructions, so you have =
> pick the right architecture/design.
>=20
> The Operating System (Call it Windows, NT, XP, or whatever) exposes to =
> the program the date information (stored on the computer's date =
hardware=20
> and software), and it exposes to the program the abilty to write files =
> to storage devides (disks, floppies, etc.)
>=20
>=20
>=20
>=20
Rob Schneider
December 5th 03, 11:02 PM
David Candy wrote:
> Expansion happens automatically with file associations. If explorer see a reg_expand registry data type it calls ExpandEnvironmentStrings. But windows is not in control in a program, the program is, So entering %time% in a File Save As dialog depend enti
rely on the program what happens. Save As just tells the programs the user typed %time% (which is a legal file name) and if the program doesn't ca;ll an expansoion functions then it will save with that name.
>
> <quote>
> I was
> really hoping that Microsoft had provided variable
> support when using Save as: to add information such as
> the date to the end of the filename.
> </quote>
>
Sorry. I read and re-read what you wrote and still didn't realize you
were referring to use of environment variables like %time%. You were
being specific and I was being generic in saying that "a program could
be written". Peace.
David Candy
December 5th 03, 11:02 PM
I realised we were at cross purposes, just couldn't work out what you =
were thinking.
--=20
David Candy
http://www.mvps.org/serenitymacros/
http://www.simtel.com/pub/pd/18669.html
"Rob Schneider" et> =
wrote in message ...
> David Candy wrote:
>=20
> > Expansion happens automatically with file associations. If explorer =
see a reg_expand registry data type it calls ExpandEnvironmentStrings. =
But windows is not in control in a program, the program is, So entering =
%time% in a File Save As dialog depend entirely on the program what =
happens. Save As just tells the programs the user typed %time% (which is =
a legal file name) and if the program doesn't ca;ll an expansoion =
functions then it will save with that name.
> >=20
> > <quote>
> > I was=20
> > really hoping that Microsoft had provided variable=20
> > support when using Save as: to add information such as=20
> > the date to the end of the filename.=20
> > </quote>
> >=20
>=20
> Sorry. I read and re-read what you wrote and still didn't realize you =
> were referring to use of environment variables like %time%. You were=20
> being specific and I was being generic in saying that "a program could =
> be written". Peace.
>=20
vBulletin® v3.6.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.