For deleting old file in batch
Closed
vishnu kumar
-
Dec 3, 2015 at 10:20 AM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Dec 3, 2015 at 03:25 PM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Dec 3, 2015 at 03:25 PM
Related:
- For deleting old file in batch
- Windows 10 iso file download 64-bit - Download - Windows
- Kmspico zip file download - Download - Other
- Gta 5 exe file download for pc - Download - Action and adventure
- Tiny 11 iso file download - Download - Windows
- Ping batch file output to text - Guide
1 response
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
149
Dec 3, 2015 at 03:25 PM
Dec 3, 2015 at 03:25 PM
Hi vishnu Kumar
I have come up with the following code. It asks for a folder path to check and delete files from. Then it confirms you want to delete the oldest file. Finally it deletes the file.
Im sure you can add a loop to make it delete files up to a desired date if you want to.
I really appreciate thank you messages as a payment for solving issues :o)
I have come up with the following code. It asks for a folder path to check and delete files from. Then it confirms you want to delete the oldest file. Finally it deletes the file.
@echo off
setlocal
CLS
set /p id=Enter path for file you want to delete:
if [%id%] == [] (
echo.
echo "you did not enter a path. Please restart this .bat file"
echo.
pause
exit
)
echo.
echo.
set Folder=%id%
set FileMask=*.*
set OldestFile=
for /f "delims=" %%a in ('dir /b /o:d "%Folder%\%FileMask%" 2^>NUL') do (
set OldestFile=%%a
)
if "%OldestFile%"=="" (
echo No files found in '%Folder%' matching '%FileMask%'!
) else (
echo "Are you sure you want to delete this file:
echo.
echo "%Folder%\%OldestFile%"
echo.
echo.
Pause
del "%Folder%\%OldestFile%"
)
Im sure you can add a loop to make it delete files up to a desired date if you want to.
I really appreciate thank you messages as a payment for solving issues :o)