Answer the question
In order to leave comments, you need to log in
How to copy files by modification date using bat?
Advise how to write a bat file that:
from %from% copies to %to% and %to2% the last file by date of change
, then to %to% and %from% leaves 5 files newer by date of change (that is, deletes files older than 5- th)
in %to2% leaves the most recent file by date of modification
My knowledge in this craft is limited to the study of the current day (I have never come into contact with this before), so I would appreciate a detailed answer with comments and examples of working code.
I would also like to know how to write a similar script using PowerShell?
Answer the question
In order to leave comments, you need to log in
Deployed will not work - there is no Windows at hand. I can give direction.
You can get a list of files sorted by modification date using the command: dir /b /a-d /od *
The /od key is responsible for sorting, you can get reverse sorting, then you need to specify the /od key. The /ad switch removes directories from the output (by default, dir also displays directories).
This command should be pushed into a loop, something like this:
for /f "tokens=* delims=" %%a in ('dir /od ...') do (
echo %%a
<тут команды тела цикла>
)
dir /?
for /?
set /?
goto /?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question