Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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 Apr 2 '13 at 9:01
    
Good idea, but the problem is that it's not just one file, but a tree of several thousand files. –  Ayman Apr 2 '13 at 9:39
    
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 Apr 2 '13 at 9:50
    
Step 4 does it on multiple files. But you have given me a great idea that would need some work. But should work. –  Ayman Apr 2 '13 at 9:55
1  
it only changed the last accessed time. creation time and modification time are not changed. do you need last accessed time in your script? –  LiuYan 刘研 Apr 2 '13 at 10:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.