Microsoft DOS
--
Questions
--
Followers
Top Experts
I need to delete all .pdf in a folder older than 24h, but I don't know much about batch files. I'll probably run it via a scheduled task.
Thanx for your expert advice.
sl
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
https://www.experts-exchange.com/questions/20292381/CMD-File-to-delete-txt-files-that-are-at-least-7-days-old.html
@ echo off
rem +=========================
rem | This package needs the new CMD.EXE extensions to be loaded and
rem | will refuse to run, if they can not be enabled.
rem +=========================
verify other 2>NUL
setLocal enableExtensions
if errorLevel 1 (
echo.
echo *ERROR*
echo.
echo Sorry - this program requires that extensions to CMD.EXE are
echo enabled. Please consult your manual for instruction on how
echo to proceed.
goto :EOF
)
set delcount=0
rem Use the DIR command to get a simple listing of file names sorted by date.
rem The file Timestamp.log marks the time when this script was last run.
rem Assuming that this was at least 24 hours ago, any files that is sorted
rem *before* the timestamp is safe to delete. When the timestamp file is
rem encountered, we are done.
for /f "delims=" %%f in ('dir /b /o:d') do (
if /i "%%f" == "Timestamp.log" goto :done
if /i "%%~xf" == ".PDF" call :delete "%%f"
)
:done
rem Update the Timestamp.log file. The update 'moves' the log file
rem ahead in the list of files sorted by date. Any PDF file modified
rem after the new timestamp will thus not be deleted the next the
rem del_marked script is run.
echo %date% %time% - deleted %delcount% files >> "Timestamp.log"
echo %date% %time% - deleted %delcount% files
goto :EOF
:delete
set /a delcount=delcount + 1
del "%~1"
goto :EOF
--
MiniMax
--
MiniMax






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I'll put my hand up on this one as well. The old "Delete my files after X many Y's" question...
pb
Happy Programming.
If you have recieved a working answer, you should close out this question yourself by accepting a comment as an answer and assigning it a grade value.
Remember that the grade you assign does not change the amount of points that you spent on the question. Instead, it changes the amount of points that the expert recieves for answering it. So please be generous to MiniMax.
Thanks,
pb

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I have same kind of problem I need 2 copy all files & folders modified not all to other network computer I already shared that directory where I want put files and folders but I need to Schedule I want this batch file run daily 11:30 pm evening .
Muhammad Amir
To schedule the batch file, you will need to use the "Scheduling Service". Look at "Control Panel"->"Scheduled Tasks" and add a new scheduled task. Since you will be sending it over the network, you will need to run the task as a user who has access to the network shares. Then you will need to modify the batchfile to either map the network drive, or specify the UNC to the shared folder.
Like this:
COPY "%FileName%" "\\Computer\Share\%FileNam
pb






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
:LoopHrs
IF /I %HR% GTR 0 (GOTO LoopDate)
SET /A HR=%HR% + 24 :: Changed from 23
SET /A DD=%DD% - 1
GOTO LoopHrs
:LoopDate
SET /A HR=%HR%
:: Added next 4 lines
IF /I %HR% EQU 24 (
SET /A HR=0 :: If at 24 hours set to 00 for midnight
SET /A DD=%DD%+1 :: Add the day back that was previously subtracted.
)
IF /I %DD% GTR 0 (GOTO DONE)
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1
FORFILES /P C:\DIRECTORY\SUB-DIRECTORY
This works for me like a charm and deletes all files in the sub-directories and all sub-sub directories older than 1 day. Look up the dos help for this command
FORFILES /?
HTH..
Sandeep
Microsoft DOS
--
Questions
--
Followers
Top Experts
Microsoft Disk Operating System (MS-DOS) was an operating system for x86-based personal computers, and traces of it are still found in the Windows operating system. DOS is still used in some embedded systems and for certain legacy 16-bit networks.