how to change the time stamp of a file ?

  • Thread starter Thread starter hon
  • Start date Start date
H

hon

hi all,

I would like to change a file's (such as text file) timestamp(the date and
time created or modified ) by script , how can i do that ?

thanks a lot
 
hon said:
hi all,

I would like to change a file's (such as text file) timestamp(the
date and time created or modified ) by script , how can i do that ?

thanks a lot

If the current date and time serves your purpose (or you're prepared to
change them temporarily to the desired date and time) you can use -

copy /b /y "your filename goes.here" +,,

To prevent the possibility of confusion, the command syntax reads -

copy<space><forward slash>b<forward
slash>y<space>"<filename>"<space><plus symbol> <comma><comma>

HTH
 
The easiest way to change the creation/modification timestamps would
be to use a utility. I've written one that will do what you ask, and
I would be happy to share it with you. Here's a sample script using
my DTstamp utility:

@echo off
:: etouch.bat by Eric Langland
:: Change a file's timestamp to the current date and time

IF "%1"=="" ECHO Usage: etouch filespec & GOTO:EOF
:: Get the date
FOR /F "tokens=2" %%A IN ('ECHO %DATE%') DO SET MyDate=%%A
:: Get the time
FOR /F "tokens=1 delims=." %%A IN ('ECHO %TIME%') DO SET MyTime=%%A
ECHO Current date/time is %MyDate% %MyTime%
ECHO/
:: Change the timestamp
ECHO Updating the timestamp on %~1 ...
C:\utils\dtstamp "%~1" -w -d %MyDate% -t %MyTime%


....and here's the syntax for DTstamp.exe:
C:\Scratch\Test Stamp Files>c:\utils\dtstamp /?

DTstamp version 1.1 by Eric Langland, 2003
Lists or changes date and time stamps on files.

Usage: DTstamp [drive:][path]filename -C -W -A -D date -T time -ISO
-FAT

-C List or change Creation date and/or time.
-W (default) List or change last Write date and/or time.
-A List or change last Access date and/or time.
-D date Change the date.
-T time Change the time.
-ISO List dates in ISO format (YYYY-MM-DD).
-FAT Attempt to list/change creation time or last access
time on
non-NTFS drives, even if not supported by the file
system.

Notes:
The filename is the only mandatory parameter. Wildcards ? and * are
accepted.
UNC network paths like \\server\share\subdirectory are accepted.

The -C, -W and -A parameters may be used in any combination. If -C,
-W and -A
are not specified, then -W is assumed.

Dates and times can be entered in a wide range of formats.
Omit both date and time to list the current date/time stamps.


My utility is not available for download because I don't have a
server, but I could email it to you if you like. Others have written
similar utilities. You might try Steve P. Miller's touch.exe, which
has more features than my utility. Steve's download page is
http://stevemiller.net/apps/ and touch.exe is part of his Win32
Console ToolBox.

Hope that helps,
Eric
 
thx for This-line-intentionally-left-blank , Dean Wells [MVP] , Eric
Langland
, actually I use sftp to get a lot of log files from others servers , but
the time is not really i want (the time i copied ) , i want the files's
attribute is the past timestamps (the date time it created) .

thx
 
what type of utility ?
is it a app or bat file ?
it looks very good

thx ,

Eric Langland said:
The easiest way to change the creation/modification timestamps would
be to use a utility. I've written one that will do what you ask, and
I would be happy to share it with you. Here's a sample script using
my DTstamp utility:

@echo off
:: etouch.bat by Eric Langland
:: Change a file's timestamp to the current date and time

IF "%1"=="" ECHO Usage: etouch filespec & GOTO:EOF
:: Get the date
FOR /F "tokens=2" %%A IN ('ECHO %DATE%') DO SET MyDate=%%A
:: Get the time
FOR /F "tokens=1 delims=." %%A IN ('ECHO %TIME%') DO SET MyTime=%%A
ECHO Current date/time is %MyDate% %MyTime%
ECHO/
:: Change the timestamp
ECHO Updating the timestamp on %~1 ...
C:\utils\dtstamp "%~1" -w -d %MyDate% -t %MyTime%


...and here's the syntax for DTstamp.exe:
C:\Scratch\Test Stamp Files>c:\utils\dtstamp /?

DTstamp version 1.1 by Eric Langland, 2003
Lists or changes date and time stamps on files.

Usage: DTstamp [drive:][path]filename -C -W -A -D date -T time -ISO
-FAT

-C List or change Creation date and/or time.
-W (default) List or change last Write date and/or time.
-A List or change last Access date and/or time.
-D date Change the date.
-T time Change the time.
-ISO List dates in ISO format (YYYY-MM-DD).
-FAT Attempt to list/change creation time or last access
time on
non-NTFS drives, even if not supported by the file
system.

Notes:
The filename is the only mandatory parameter. Wildcards ? and * are
accepted.
UNC network paths like \\server\share\subdirectory are accepted.

The -C, -W and -A parameters may be used in any combination. If -C,
-W and -A
are not specified, then -W is assumed.

Dates and times can be entered in a wide range of formats.
Omit both date and time to list the current date/time stamps.


My utility is not available for download because I don't have a
server, but I could email it to you if you like. Others have written
similar utilities. You might try Steve P. Miller's touch.exe, which
has more features than my utility. Steve's download page is
http://stevemiller.net/apps/ and touch.exe is part of his Win32
Console ToolBox.

Hope that helps,
Eric


"hon" <[email protected]> wrote in message
hi all,

I would like to change a file's (such as text file) timestamp(the date and
time created or modified ) by script , how can i do that ?

thanks a lot
 
I am having some trouble understanding your question. If I have it right,
1. You have some log files from other servers.
2. The log files now have timestamps according to the time you copied them.
3. You want to change the timestamp for each log to the time when it was
created.

Can you tell us how we can find out when the log was created? I could imagine
at least two possibilities:
1. Look at the file's creation timestamp.
2. Look at the data inside the file.
 
My DTstamp.exe and Steve P. Miller's Touch.exe are both console applications.
what type of utility ?
is it a app or bat file ?
it looks very good

thx ,

Eric Langland said:
The easiest way to change the creation/modification timestamps would
be to use a utility. I've written one that will do what you ask, and
I would be happy to share it with you. Here's a sample script using
my DTstamp utility:

@echo off
:: etouch.bat by Eric Langland
:: Change a file's timestamp to the current date and time

IF "%1"=="" ECHO Usage: etouch filespec & GOTO:EOF
:: Get the date
FOR /F "tokens=2" %%A IN ('ECHO %DATE%') DO SET MyDate=%%A
:: Get the time
FOR /F "tokens=1 delims=." %%A IN ('ECHO %TIME%') DO SET MyTime=%%A
ECHO Current date/time is %MyDate% %MyTime%
ECHO/
:: Change the timestamp
ECHO Updating the timestamp on %~1 ...
C:\utils\dtstamp "%~1" -w -d %MyDate% -t %MyTime%


...and here's the syntax for DTstamp.exe:
C:\Scratch\Test Stamp Files>c:\utils\dtstamp /?

DTstamp version 1.1 by Eric Langland, 2003
Lists or changes date and time stamps on files.

Usage: DTstamp [drive:][path]filename -C -W -A -D date -T time -ISO
-FAT

-C List or change Creation date and/or time.
-W (default) List or change last Write date and/or time.
-A List or change last Access date and/or time.
-D date Change the date.
-T time Change the time.
-ISO List dates in ISO format (YYYY-MM-DD).
-FAT Attempt to list/change creation time or last access
time on
non-NTFS drives, even if not supported by the file
system.

Notes:
The filename is the only mandatory parameter. Wildcards ? and * are
accepted.
UNC network paths like \\server\share\subdirectory are accepted.

The -C, -W and -A parameters may be used in any combination. If -C,
-W and -A
are not specified, then -W is assumed.

Dates and times can be entered in a wide range of formats.
Omit both date and time to list the current date/time stamps.


My utility is not available for download because I don't have a
server, but I could email it to you if you like. Others have written
similar utilities. You might try Steve P. Miller's touch.exe, which
has more features than my utility. Steve's download page is
http://stevemiller.net/apps/ and touch.exe is part of his Win32
Console ToolBox.

Hope that helps,
Eric


"hon" <[email protected]> wrote in message
hi all,

I would like to change a file's (such as text file) timestamp(the date and
time created or modified ) by script , how can i do that ?

thanks a lot
 
Back
Top