I have two folders in C:
drive.
I want to copy top 15 txt files from one folder to another folder. It is a daily repetitive task so I want to automate the process.
How can I copy those txt using batch script?
This is what I have but it does not work.
xcopy /s "C:\Documents" "C:\research"
@echo off
setlocal EnableDelayedExpansion
set "i=0"
for /F "delims=" %%a in ('dir "C:\Documents" /O:-D') do if !i! lss 15 (
copy "%%a" "C:\research"
set /A i+=1
)
You may also add the /T
switch in dir
command to select the specific date used (creation, last access or last mod).
I'd check this out:
Batch file to copy files from one folder to another folder
I think this is what you're looking for but I'm not sure it'll guarantee the first 15 files.
Since you don't have spaces the "" aren't required.
xcopy /s C:\Documents\*.txt C:\research\*.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.