Reputation: 37
when you run this script in a folder with various files it makes a copy of the file name and adds a .txt ext to it, then places the below comments inside the .txt file.
This only works on file within the folder you run the script. I need help to ammend this script so that it applies to all files in that folder as well as all files in subfolders of this folder you're running it from.
Is that possible?
@echo off
for /f "delims=" %%a in ('dir /b /a-d ') do (
echo creating "%%a.txt"
>"%%a.txt" echo This file has been removed to free space on the Shared Drive. Contact Tech Department for Restore queries.
rem to delete all the original files you can un-comment the following line by removing the rem
rem del "%%a"
)
popd
Upvotes: 0
Views: 36
Reputation: 56198
with a little change, this is able to process only files, that are older than x days (30 in this example), I feel as this would make sense in your case.
@echo off
for /f "delims=" %%a in ('forfiles /S /D -30 /c "cmd /c if @isdir==FALSE echo @path"') do (
echo creating "%%~a.txt"
>"%%~a.txt" echo This file has been removed to free space on the Shared Drive. Contact Tech Department for Restore queries.
rem to delete all the original files you can un-comment the following line by removing the echo
echo del "%%~a"
)
(sorry, should be a comment, but then would be unreadable)
Upvotes: 0