Windows attrib command changes file timestamp

0

I have some batch file running that does the following on a directory tree with several thousand files:

  1. change file attributes, turn OFF readonly
  2. do some stuff, add new files.
  3. change file attributes, turn ON readonly bit
  4. For newer files that were added from 2, do some long operation.

The problem I am facing is that steps 1 and 3 also change the file timestamp. which causes step 4 to be run unnecessarily. I do need the files to be readonly after the job is run.

I tried chmod from cygwin, and that did not work.

Using Windows XP.

Ayman

Posted 2013-04-02T08:45:00.220

Reputation: 215

You could store the timestamp of the file in a variable before changing the attributes and then use the stored timestamp to determine wether the file is new or not. Also, unix command touch (included in cygwin), with the option -t followed by the desired time, sets the file timestamp accordingly. – Pincopallino – 2013-04-02T09:01:37.547

Good idea, but the problem is that it's not just one file, but a tree of several thousand files. – Ayman – 2013-04-02T09:39:02.207

Does the step 4 do its work on a single file or it works on multiple files at the same time? In the first case, you create a script that does the four steps on a file that is passed as a parameter, and then you cycle this script to all the files in the folder. In the second case, you could do like this: for each file, you get the timestamp and store it to a variable, then you do steps 1 through 3, and then you restore the stored filestamp using the touch command. The problem here is that the format accepted by touch might be different from the output . – Pincopallino – 2013-04-02T09:50:49.307

Step 4 does it on multiple files. But you have given me a great idea that would need some work. But should work. – Ayman – 2013-04-02T09:55:38.583

Ok. You might also consider using a more powerful scripting tool, like Microsoft Powershell, which is free to download for Windows XP and integrated in new Windows versions. It is a command prompt which integrates advanced and powerful scripting and programming features. – Pincopallino – 2013-04-02T10:00:40.723

1it only changed the last accessed time. creation time and modification time are not changed. do you need last accessed time in your script? – LiuYan 刘研 – 2013-04-02T10:15:41.633

You can list the files with the dir /t command option. (on NTFS formatted HD's) – Endoro – 2013-04-02T15:53:17.810

No answers