2

I have a folder with a large number of files, these file will be periodically deleted using date time (old will be removed automatically).

I need to keep some files inside this folder and prevent them from being deleted automatically updating the date time of file.

The names of files to keep updating the date time are saved in a text file that contains only the file name to keep updating the date time of files.

My OS is Windows 7 32 bit language Italian

I add an example:

folder that contains all files:

log1.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎00:00:00
log2.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎00:03:00
log3.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎00:06:00
log6.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎00:08:00
log7.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎00:30:00
log9.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎00:40:00
log152.txt modified date lunedì ‎1 ‎gennaio ‎2019, ‏‎01:10:00

Content of list.txt with the files name to update modified date time:

log7.txt
log152.txt
log555.txt
log785.txt
log10150.txt

In this case after run the bat file these files need date time to update at today/now date time

log7.txt modified date venerdì ‎4 ‎ottobre ‎2019, ‏‎16:00:00 (today)
log152.txt modified date venerdì ‎4 ‎ottobre ‎2019, ‏‎16:00:00 (today)

All others files should not be changed when not included in the list of files to be updated.

The folder that contains the file to update have spaces in path.

The list of files to update is saved in different folder.

This is the code i tried it copy the files in the same folder to update the date time but i need to update only files names saved in text list.

cd C:\Users\Windows\Desktop\test
copy C:\Users\Windows\Desktop\test,,+
2

This is possible using the Nirsoft freeware tool nircmd.

Assuming that the file list.txt contains the list of file-names, the following batch file will set them all to the current date-time:

@echo off
setlocal enabledelayedexpansion
for /f %%G in ('type "C:\path\to\list.txt"') do (
  "C:\path\to\nircmd.exe" setfiletime "%%G" now now
)

Or with your code, noting that the copy solution is limited to working only in the current folder:

@echo off
setlocal enabledelayedexpansion
for /f %%G in ('type "C:\path\to\list.txt"') do (
  copy "%%G",,+
)
  • If it's possibile i prefer a solution directly with bat file excluding external software. I added the code i used to update the date time, simply I used copy function to overwrite the date time of the file i need only to select the files to update from a test list, see the code i added please. – pachiro Oct 4 '19 at 19:39
  • The code can be adapted. – harrymc Oct 4 '19 at 19:43
  • Hi @harrymc i have path of folder and list with space and give me an error. can you adapt the code to set the path with space for folder and path with space for list.txt please ? With path with space your code give me error. Path folder: D:\Programmi Installati\MyFolder and path list: D:\Programmi Installati\list.txt – pachiro Oct 4 '19 at 21:01
  • Modified as to deal with blanks. – harrymc Oct 5 '19 at 6:39
  • It's possible to add the folder path too in your code ? Path folder: D:\Programmi Installati\MyFolder and path list: D:\Programmi Installati\list.txt in this mode i can run the batch file from every folder i want and it working in correct folder. Warning at the space in path. Thanks – pachiro Oct 5 '19 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.