file manipulation of dates and times - Page 1
Forum section: electronics / general

author: free_electron
author_rank: Super Contributor
timestamp: March 23, 2022, 05:33:09 am
content: I'm looking for a way to overwrite a file without altering the timestamps associated with it ( creation , last modified, date accessed. windows keeps 3 timestamps )lets say i have a file called a.dat. i want to overwrite it with a new a.dat but keep the three timestamps from original a.dati'm trying to fool a version control system (not sourcecode). it keeps track of the timestamps. if i add a revision the master database (an oracle contraption) gets updated to the new file and this causes a whole chain of events i do not want to trigger. (it sends linked data through a revision-release cycle which is very time consuming and unnecessary. i am trying to fix a corrupted a.dat file. i have a correct working file , i just need away to overwrite a.dat without the operating system altering the timestamps. The files are plain ascii text and contain some xml data that populate fields in the database. the corrupted a.dat is blank (0 bytes).I can solve the issue by simply overwriting the current version with new data but i need to be able to retain the three timestamps while the application and database is idle.sidenote : i cannot do this outside of windows so don't suggest things like "boot a linux live cd and yadda ..." this thing runs on a windows 2019 enterprise server. no rebooting allowed.https://docs.microsoft.com/en-us/windows/win32/sysinfo/file-times?redirectedfrom=MSDN

author: Ian.M
author_rank: Super Contributor
timestamp: March 23, 2022, 06:10:31 am
content: You could use a Windows port of the Linux/Unixtouchcommand, or run Linux touch under WSL. It would go something like:Code:touch -r a.dat tstamp.tmpcopy /y new_a.dat a.dattouch -r tstamp.tmp a.datdel /q tstamp.tmpwhich usestouch -rto save a copy of the original file's timestamps, replaces the original file then resets its timestamps from the copy and finally cleans up.Similar timestamp manipulation can be done in Windows Powershell if you cant install 3rd party executable utilities, bu the syntax and command sequence to do so is very different and far more complex.

author: PKTKS
author_rank: Super Contributor
timestamp: March 23, 2022, 11:00:51 am
content: Quote from: free_electron on March 23, 2022, 05:33:09 amDUMP all this MS garbage... they removed all the tools (like attrib)..they did never supported CYGWIN..and now these assholes want to sell thatpiece of shitcrock of shit WSL...pleaesssaseeee.. go the properRATIONALway..TRIVIAL DO DA DIIIICode:open PIPE, "find . -type f -printf '%T+ %p\n' |" or die('Failed to open PIPE');while(<PIPE>) {print STDERR 'WILL TOUCH --no-create --date=\''."$1-$2-$3 $4:$5:$6\' on file $8"if ( m/([0-9]{4}?)\-([0-9]{2}?)\-([0-9]{2}?)\+([0-9]{2}?)\:([0-9]{2}?)\:([0-9]{2}?)(\.[0-9]{10}?)(.*)/ );}close PIPE;wait;Paul

author: thinkfat
author_rank: Unknown
timestamp: March 23, 2022, 11:07:31 am
content: QuoteQuote from: PKTKS on March 23, 2022, 11:00:51 am

author: PKTKS
author_rank: Super Contributor
timestamp: March 23, 2022, 11:11:01 am
content: Quote from: thinkfat on March 23, 2022, 11:07:31 amRIPI was there .. kinda early 90s...Made a considerable effort to get rid of all MS my hardware ..my business my life .. and my family..they gave me just prejudice... and problemsand today even free of these filthy things... I still deal with them..Nevertheless.. i no longer have anything left..but took me quite an effortPaul

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: March 23, 2022, 01:53:42 pm
content: Quote from: thinkfat on March 23, 2022, 11:07:31 amHave to say when I read the OP, I felt pain. If he says he can't reboot, I wonder what limited access he would have to permissions hackery.https://www.online-tech-tips.com/computer-tips/how-to-change-the-last-modified-date-creation-date-and-last-accessed-date-for-files-and-folders/

author: free_electron
author_rank: Super Contributor
timestamp: March 23, 2022, 01:59:50 pm
content: Quote from: Ed.Kloonk on March 23, 2022, 01:53:42 pmi can reboot if i wanted. i'm a full admin, but i don't want to reboot

author: free_electron
author_rank: Super Contributor
timestamp: March 23, 2022, 02:01:35 pm
content: Quote from: PKTKS on March 23, 2022, 11:00:51 amGlad it works for you. i won't touch it with a long pole. i run programs. programs that don't exist elsewhere but windows.

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: March 23, 2022, 02:06:30 pm
content: Quote from: free_electron on March 23, 2022, 01:59:50 pmThen perhaps you're stuck with hitting the win API with some code. Don't know.

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: March 23, 2022, 02:10:00 pm
content: Thinking out side the square a bit, can you by any chance access the disk at the byte level? Make a VM and try and attack the metadata that way. I wonder if winders has CRC or anything on the files.

author: coromonadalix
author_rank: Super Contributor
timestamp: March 23, 2022, 02:34:56 pm
content: Playing with time stamp in a server machinesorry thats a no go, you have to keep tracks of the change EVEN if you have to patch a file or restore it to a working status.You do know some antivirus or scanning tools will see a file change EVEN with properly patched time stamps, your corrected / corrupted file could go away ??I understand the need, but the implications / corrections / and bypassing to avoid supplemental work is a noYou dont play like that in a server ...I have a server running, i have an entreprise antiviral scanner (i wont disclose the name) who has an hash file verification with time stamps and a few other things, if i play with a file, It will ask if i recognize it, and ask to authorize it and will do an re-hash to update its database ...my 2 cents

author: PKTKS
author_rank: Super Contributor
timestamp: March 23, 2022, 03:01:26 pm
content: Quote from: coromonadalix on March 23, 2022, 02:34:56 pmWelll ... for sure sooner or later anyone may find a common date time issue...that happens when some of those odd things screw the RTC and the system boots...Now.. ON ANYNON SYSTEMD SERVER.. a screwed RTC willHALTthe boot in the first line of rc.S.. and just a few filetime stampswill be corrupted...ONSYSTEMD servers..that is a totaltrain wreckage...You can not stop the boot RC levels andyou can not see the wrong timestamp...As soon as you enter aworkingsessionALL YOUR SYSTEM IS F****all your dates may be reset to 1970. or 1990...LOG files .. CONFIG files...been there.. fortunately my servers do not use SYSTEMD and RC.S stops the boot entering a server admin session..So we can restore all affected files ( assume you can find them using a smart script )and restore proper dates...Other nasty case is TAR files withFUTUREdates.. ( please tell the MF to **** )very common dumb TAR files with future dates messing your file systems with odd errors.It happens ..you know... YOU NEED THE TOOLS TO KEEP YOUR (computer)TOOLworking..... And the MS BOZOS removed all the tools to sell them like services...fill the blanks ( please go. )Paul

author: PKTKS
author_rank: Super Contributor
timestamp: March 23, 2022, 03:11:31 pm
content: Quote from: free_electron on March 23, 2022, 02:01:35 pmWorks for anyone.. just need the tool there...CYGWIN could do this at late 199x..MS screwed CYGWIN.. never supported the tools..just removed them all.. making an empty sack of problems ..You can just do it today as it was possible since 90s with CYGWIN.no need to WSL or any other tool...Just track the tips...PaulPS/1 they are on the gaming a long time...http://cygwin.org/PS/2 ALAS for the record...Istillhave somewhere around here .. a 32 bit working saved image of w98x and w2000s 32 bit from the last time I dumped them... at the time a full working 32bit CYGWIN install allowed me to move all my win DOS deprecated stuff to Slackware and Debian... (before Debian went systemd)so.. it works even in 32bit systems FULL POSIX compliant systems

author: T3sl4co1l
author_rank: Super Contributor
timestamp: March 23, 2022, 04:22:16 pm
content: Well... anyway...FWIW, as I recall, file attributes (including times) are freely accessible in the File API. Just another thing you can write. I mean, how else would you expect ZIP files to extract with their original dates, clearly they're new files, but also, they are the originals, right? So yeah, it's always been something handy. Hmm, I forget how this works back in ye olde DOS, but yeh that's a thing too.As for not having to write the whole file-tweaker app yourself, it seems all you need is Google? Top hit:https://www.quora.com/How-do-I-edit-a-file-without-changing-the-timestamplinks to:https://tools.stefankueng.com/SKTimeStamp.htmlSounds promising, anyway.Maybe you don't want to restore the original attributes, you need it done "in place". Dunno, but it's probably also been done. I just peeked at the top hits:https://www.google.com/search?q=windows+modify+file+without+updating+timeTim

author: PKTKS
author_rank: Super Contributor
timestamp: March 23, 2022, 05:37:37 pm
content: just fixing a minor detail - the quoting for proper shell interpretation..Fixed the other above as well.. all POSIX shells should fine with this quotingCode:open PIPE, "find . -type f -printf '%T+ %p\n' |" or die('Failed to open PIPE');while(<PIPE>) {print STDERR 'WILL TOUCH --no-create --date=\''."$1-$2-$3 $4:$5:$6\' on file $8"if ( m/([0-9]{4}?)\-([0-9]{2}?)\-([0-9]{2}?)\+([0-9]{2}?)\:([0-9]{2}?)\:([0-9]{2}?)(\.[0-9]{10}?)(.*)/ );}close PIPE;wait;Paul

author: free_electron
author_rank: Super Contributor
timestamp: March 23, 2022, 08:38:16 pm
content: Quote from: coromonadalix on March 23, 2022, 02:34:56 pmI'm not playing with a time stamp. i do not want to alter the time stamp , i want to RETAIN it and just modify the contents of the file.Here's the backdrop.the file in question is a table template and contains some ascii textCode:Voltage,*Power,*Wattage,*Manufacturer,*Manufacturer part number,*and so on.Due to a dropped network connection a number of these templates got saved empty. I have the working copies (but they have an older timestamp)There are over 9000 resistors connected to this template. (this is a CAD library)if i touch the template in the application i need to rerun the release cycle on all these parts , elevate them back to production and it causes 9000 revisions to be written in the database. this in turn knocks any project using those revisions out-of-date. i don't want to deal with that mess.The application monitors timestamps of the template files. a change of the timestamps triggers the entire cycle.So my idea is to shut down the application, overwrite the file while retaining the timestamps and restarting the application again.Problem solved.The other route would be to stop the application , overwrite the file with a more recent timestamp , fire up SQL and bang on the oracle database and set the timestamp stored in there there to the stamp of the new file. the oracle database stores the most recent file timestamp in a specific field. Problem is the layout and inner workings of that thing are not known. So there may be many locations that need to be touched...going the disk route looks simpler.i may have to do this with a disk editor. many of these tools you find on the internet can only work at the h:m:s level. i want the entire field down to the 100ns resolution.

author: Halcyon
author_rank: Unknown
timestamp: March 24, 2022, 05:00:24 am
content: MAC times are a function of the file system and nothing to do with the file itself (as opposed to metadata like EXIF), but there are Windows tools which will allow you to "fake" those dates and write those attributes to the file system. One I've used before isNirsoft FileDate Changerbut I haven't used it for years (and it's latest release is very old), so I don't know if it will work on modern versions of Windows.

author: bw2341
author_rank: Regular Contributor
timestamp: March 24, 2022, 05:14:42 am
content: https://www.ghacks.net/2017/10/09/how-to-edit-timestamps-with-windows-powershell/I'm a complete PowerShell novice, so test this carefully before trying it on your server.By fumbling around, I think I have what you need to do what you want.Code:(Get-Item .\test.txt).Creationtime | Get-Date -Format o(Get-Item .\test.txt).LastAccessTime | Get-Date -Format o(Get-Item .\test.txt).LastWriteTime | Get-Date -Format oIn my testing, this outputs the timestamps in a timestamp String object like this:Code:2022-03-24T00:52:38.8254626-04:00So by the example from the linked webpage you should be able to set the timestamps to anything you want like this:Code:$(Get-Item .\test.txt).CreationTime =$(Get-Date "2010-03-14T12:23:34.5678901-04:00")$(Get-Item .\test.txt).LastAccessTime =$(Get-Date "2010-03-14T12:23:34.5678901-04:00")$(Get-Item .\test.txt).LastWriteTime =$(Get-Date "2010-03-14T12:23:34.5678901-04:00")It seems to work in my testing.If you have a copy of the correct file with the correct timestamps, you could also tryrobocopysince it can preserve all the timestamps.

author: Berni
author_rank: Super Contributor
timestamp: March 24, 2022, 06:54:52 am
content: One way you can also make sure you got your timestamp modification working 100% is opening the raw disk in WinHex (https://www.x-ways.net/winhex/). It can read the common file systems, letting you wander around them. So it can take you directly to the raw hex of the directory entry for that file. If the entry is binary identical then you know nothing about the file metadata has changed.In theory you could also overwrite the directory entry directly in hex, but that is probably a pretty bad idea to try on something live. The actual intended use for this filesystem parsing feature of WinHex is digital forensics, letting you recover old deleted data manually.

author: PKTKS
author_rank: Super Contributor
timestamp: March 24, 2022, 09:57:10 am
content: Quote from: free_electron on March 23, 2022, 08:38:16 pmMy tinysolutionabove did not popped from the void...I use a very similar schema to prevent changes in my own in_office distro to trigger new builds...So.. what i do .. is to dump in a file a list of the timestamps.. (using the command above..)and then.. i can change whatever i want... and then just run the very same script ...But this time I will fix the dates using the saved file as template...a at will..Of course anyone can do this.. but you NEED THE POSIX TOOLSbottom line... grab a full set of CYGWIN. (not crappy WSL)and you can do the job in MS*** as I can in both... NIX and ***For example here is a sample of the huge... timestamp fileCode:2021081918422002.CORE/installation-log.iana-etc-2.302021081918430502.CORE/installation-log.procps-3.2.82021081918442602.CORE/installation-log.module-init-tools-3.02021081919044602.CORE/installation-log.perl-5.32I have others to control permissions...as the builds are automated... there are chances to have issues..the logs are very important and timestamps critical for the build dependencyPaul

author: free_electron
author_rank: Super Contributor
timestamp: March 24, 2022, 04:03:20 pm
content: - solved -I made a copy of my working files to a different computer (i did not want to do the editing directly on the server. don't want to install foreign software there.)I altered the timestamp bytes on these copies with a disk editor. Verified they still looked ok and could be accessed.From looking in the database it seems like it only stores the 'last modified' stamp. That is the only timestamp found and it matches the stamp on the file. anyway , i copied all three fields.i zipped the files ( 7-zip will restore the stamps on unpacking . i tried this. so that made sure the stamps would travel with the files.)I stopped the application. deleted the old files then restored from my ZIP file. All works fine. it's none the wiser something happened.The programs like nirsoft and attributechanger only seem to work at HMS level. The remaining bytes are set to 00seehttps://www.meridiandiscovery.com/articles/date-forgery-analysis-timestamp-resolution/It may be that the application only checks HMS but i did not want to take any chances. in any case i had a backup of the entire system.

author: Bud
author_rank: Super Contributor
timestamp: March 24, 2022, 04:41:33 pm
content: Quote from: PKTKS on March 23, 2022, 11:00:51 amIf this pile of gibberish is "trivial" then i do not know what is not.

author: PKTKS
author_rank: Super Contributor
timestamp: March 24, 2022, 05:56:47 pm
content: Quote from: Bud on March 24, 2022, 04:41:33 pmI understand the rant...Trust me.. that simple script is trivial...You are required to do that by hand instantly and in varying alternatives ways..if you decide to be up to the task of managing a "screwed" server...that failed to boot with bad RTC.. mismatched file system timestamps..you will fallback to a single session terminal - no fancy girly toys and GUI..BUT ALL THE TOOLS ARE THERE..in 15 minutes a competent folk can fix almost anything... unless hardware faults..This is simple.. but PERL takes time to master.I am not even CLOSE to the real master folks in PERL..as a matter of fact.. this is meant to be written as a single-liner command..full check and fix over the target branch...It can also be written in AWK.. although it will look much worse than thatPaulPS/ BTW... i am not aprogrammer..i am EE specialized in ITit happens that i do this over several decades... called experience

author: thinkfat
author_rank: Unknown
timestamp: March 24, 2022, 06:05:41 pm
content: And still, flexing your l337 sk1llz will not help the OP one bit.

author: PKTKS
author_rank: Super Contributor
timestamp: March 24, 2022, 06:09:42 pm
content: Quote from: thinkfat on March 24, 2022, 06:05:41 pmyep I got that point...He just will not track CYGWIN ..he will carve the best way to do that on bare grass WinOS...been there late 80s.. early 90s.. until I decided to ditch my SCO with Slackware and dump MSi got that.. but.. nevertheless.. I tried to give directions...may be some future day or other folks can track the tipsPaul

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: March 24, 2022, 07:24:48 pm
content: Quote from: free_electron on March 24, 2022, 04:03:20 pmGlad you got it sorted.