Page 1 of 1 1
Topic Options
#157207 - 2006-02-14 05:56 PM How to change a file date/time?
Flavien Offline
Getting the hang of it

Registered: 1999-07-21
Posts: 95
Loc: Geneva, Switzerland
I'm trying to find a way to change a file time and/or date. I've found many command line tools, but none were free. Is there a way to do it (WMI, FileSystemObject, ?) or a link to a free (GPL) command line tools?

Some references:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/setfiletime.asp
http://msdn.microsoft.com/library/defaul...urrent_time.asp

My goal is to modify some files (e.g.: convert .doc -> .txt) and then change the new files to reflect the old files date.

Thank you very much in advance!

Top
#157208 - 2006-02-15 09:24 AM Re: How to change a file date/time?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Search around for a Windows port of "touch" - it is a command line program which originated on *nix systems but you will find DOS/Windows ports of it all over the place, and they are free.

It quite often comes in a "fileutils" package which includes many other utilities that make life so much easier.

One example is here: http://gnuwin32.sourceforge.net/packages/coreutils.htm

This package includes the following:
Quote:

File utilities:

chgrp: Changes file group ownership.
chown: Changes file ownership.
chmod: Changes file permissions.
cp: Copies files.
dd: Copies and converts a file.
df: Shows disk free space on filesystems.
dir: Gives a brief directory listing.
dircolors: Setup program for the color output of GNU ls.
du: Shows disk usage on filesystems.
install: Copies file and sets its permissions.
ln: Creates file links.
ls: Lists directory contents.
mkdir: Creates directories.
mkfifo: Creates FIFOs (named pipes).
mknod: Creates special files.
mv: Moves files.
rm: Removes (deletes) files.
rmdir: Removes empty directories.
shred: Destroy data in files.
sync: Synchronizes filesystem buffers and disk.
touch: Changes file timestamps.
vdir: Long directory listing.

Text utilities:

cat: concatenates and prints files on the standard output
cksum: checksum and count the bytes in a file
comm: compares two sorted files line by line
csplit: splits a file into sections determined by context lines
cut: remove sections from each line of files
expand: convert tabs to spaces
fmt: simple optimal text formatter
fold: wrap each input line to fit in specified width
head: output the first part of files
join: join lines of two files on a common field
md5sum: compute and check MD5 messsage digest
nl: number lines of files
od: dump files in octal and other formats
paste: merge lines of files
ptx: produce a permuted index of file contents
pr: convert text files for printing
shasum: compute and check SHA1 message digest
sort: sort lines of text files
split: split a file into pieces
sum: checksum and count the blocks in a file
tac: concatenates and prints files in reverse
tail: outputs the last part of files
tr: translates or deletes characters
tsort: perform topological sort
unexpand: convert spaces to tabs
uniq: remove duplicate lines from a sorted file
wc: prints the number of bytes, words, and lines in files

Shell utilities:

[ - Check file types and compare values
basename - Removes the path prefix from a given pathname.
chroot - Changes the root directory.
date - Prints/sets the system date and time.
dirname - Removes the last level or filename from a given pathname.
echo - Prints a line of text.
env - Displays/modifies the environment.
expr - Evaluates expressions.
factor - Prints prime factors.
false - Returns an unsuccessful exit status.
groups - Print the groups that the user is a member of.
hostid - Print the numeric identifier for the current host
hostname - Print or set the machine name.
id - Print real/effective uid/gid.
logname - Print current login name.
nice - Modify scheduling priority.
nohup - Allows a command to continue running after logging out.
pathchk - Check file name portability.
pinky - Lightweight finger
printenv - Prints environment variables.
printf - Formats and prints data.
pwd - Print the current working directory.
seq - Print numeric sequences.
sleep - Suspends execution for a specified time.
stty - Print/change terminal settings.
su - Allows you to adopt the id of another user or superuser.
tee - Sends output to multiple files.
test - Evaluates an expression.
true - Returns a successful exit status.
tty - Print terminal name.
uname - Print system information.
users - Print current user names.
who - Print a list of all users currently logged in.
whoami - Print effective user id.
yes - Print a string repeatedly.




If you only want a simple program without the install/DLL register hassle you will be able to find it with a little searching.

Update: I've just come across a comment that MS includes a port of TOUCH.exe in it's toolkits.

Top
#157209 - 2006-02-15 09:32 AM Re: How to change a file date/time?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here is a link to a method using Shell.Application to set the date - I've not tried it so I can't comment further:
http://msdn.microsoft.com/library/defaul.../modifydate.asp

Top
#157210 - 2006-02-16 05:38 AM Re: How to change a file date/time?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Well here is a nice little Windows application to modify the DATE/TIME - there is also a nice little PATH COPY utility here, both are FREE

http://home.worldonline.dk/ninotech/index.htm

http://home.worldonline.dk/ninotech/freeutil.htm


Edited by NTDOC (2006-02-16 05:40 AM)

Top
#157211 - 2006-02-16 11:26 AM How to change a file date/time: the answer
Flavien Offline
Getting the hang of it

Registered: 1999-07-21
Posts: 95
Loc: Geneva, Switzerland
Voilà, this works:

Code:
;ModifyFileDate - Modify a file date and time.
Function ModifyFileDate($file, Optional $date)
;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/folderitem/modifydate.asp
;Quick and dirty function, the $date format depends on the local settings,
;but this works when we need to re-apply the same date after having modified a file.
Dim $object, $file_path, $file_name, $object_path, $folder_item
$file_path = SubStr($file, 1, InStrRev($file, "\") - 1)
$file_name = SubStr($file, InStrRev($file, "\") + 1)
$object = CreateObject("Shell.Application")
$object_path = $object.NameSpace($file_path)
If $object_path <> ""
$folder_item = $object_path.ParseName($file_name)
If $folder_item <> ""
$ModifyFileDate = $folder_item.ModifyDate
If IsDeclared($date)
$folder_item.ModifyDate = $date
EndIf
EndIf
EndIf
EndFunction



I'm too lazy to put it in the UDF section...

Top
#157212 - 2006-02-16 11:53 AM Re: How to change a file date/time: the answer
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Cool
Just one small note.
This can easily be used for forging file dates so it's useable for "criminal" actions. Not encouraging anybody to do so or saying you do this but just making a comment. Don't take it personal it’s just something that came up when I read at this thread. For sure there are many legitimate tasks where this can be used for.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157213 - 2006-02-16 12:53 PM Re: How to change a file date/time: the answer
Flavien Offline
Getting the hang of it

Registered: 1999-07-21
Posts: 95
Loc: Geneva, Switzerland
Mart, this is a valid point, I've been wondering if someone would first ask me the purpose of my initial request...

A good use of this would be, for example, this Office 2000 problem:
Full-file version update may request Office source files
http://support.microsoft.com/kb/840169/

Another usage is for doing a mass modification of many user's documents. When doing so, suddendly the user would believe her files were all messed up, and would certainly confuse the result of a file search.

Top
#157214 - 2006-02-16 01:59 PM Re: How to change a file date/time: the answer
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yep. Those are indeed valid cases. Like said there are also people wanting to give files false dates for personal gain. This is wrong but impossible to stop from happening so I would not worry about it much.

Putting it into a UDF would be nice and easy for any other user wanting/needing to change the file date. No need to remember the complete code then.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#206918 - 2013-03-14 10:24 PM Re: How to change a file date/time: the answer [Re: Mart]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol. I need this exactly for office 2010.
my issue was that: c:\Program Files\Common Files\Microsoft Shared\web server extensions\40\bin\fp4autl.dll was missing on XP machine, so installer failed with error "access denied, replacing file"

stupid microsoft. anywho... just put a text file there, but this way it didn't get updated, as the file was too new.
_________________________
!

download KiXnet

Top
#206919 - 2013-03-14 10:49 PM Re: How to change a file date/time: the answer [Re: Lonkero]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Would Touch work?

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=188150
_________________________
(... better days ahead)

Top
#206920 - 2013-03-15 03:42 AM Re: How to change a file date/time: the answer [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sweet. I knew we had something like that, just didn't look in the correct place. thanks Allen. seems to be "just like" the one in this thread.

Edited by Lonkero (2013-03-15 04:35 AM)
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 584 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.067 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org