Solved Move only 2 files base on filename in folder.

July 20, 2012 at 08:19:01
Specs: WinXP,Win7,WinNT
Hi,

I just can't find a batch file on what I need.

Currently, I have a folder with over 100 files.

Example
c:/folder/filefolder
filename_05.csv
filename_06.csv
filename_07.csv
filename_08.csv
filename_09.csv
filename_10.csv
filename_11.csv
etc....

need to move only 2 files, with is the top 2 files sort by filename in the folder to another folder.
which is

c:/folder

After moving.

c:/folder/filefolder
filename_07.csv
filename_08.csv
filename_09.csv
filename_10.csv
filename_11.csv
etc....


c:/folder
filename_05.csv
filename_06.csv

Thanks.
Jeremy


See More: Move only 2 files base on filename in folder.

Report •

#1
July 20, 2012 at 17:19:42
✔ Best Answer
@echo off & setlocal enabledelayedexpansion
set c=0
for /f %%a in ('dir /b /o:n folder\filefolder\filename_*.csv') do (
move %%a \folder
:or: move /y %%a \folder if you want to possibly write over existing files
set /a c+=1
if !c! equ 2 goto :eof
)
:end
not tested

Report •

#2
July 23, 2012 at 03:30:33
Hi nbrane,

Thank you.

Jeremy


Report •
Related Solutions


Ask Question