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,,+ 

1 Answer

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",,+ ) 
6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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