Move the first file in a folder

May 13, 2009 at 15:38:12
Specs: Windows XP

I just need to separate(move) one file from a folder containing n (n>=1) number of files to a different folder
eg: Folder A has
move I1.txt to folderB .
Please note : file names are dynamic so I cannot look for file stating with I1* . Regardless of file name and extension , move one file from the folder.

See More: Move the first file in a folder

Report •

May 13, 2009 at 19:13:05
Here's one way, change copy to move when you're finished testing:

@echo off

for /f "delims=*" %%1 in ('dir /b a\') do (
    copy "%%1" b\ > nul & exit /b

Report •

May 14, 2009 at 10:46:50
Depends on how you define first.

If at first you don't succeed, you're about average.


Report •

May 14, 2009 at 12:21:44

Thanks for your reply..But somehow I was not able to use the code because it was throwing me error saying system could not find the specified file.. came up with the following code which is working..Thanks all ..
here is my code I dont know how good it is but serves my purpose ..
REM This is to copy all to an archive folder and move first file regardless of name & extn to a different folder and move rest of files to another folder.
set dr_cb=C:\prc
set drcb_O8322=C:\out\archive
set drcb_O832T1=C:\Temp1
set drcb_O832T2=C:\Temp2
Set fnam_cb=I*
set l_cbcon=('"dir /B /A:-D %dr_cb%\I*"')
FOR /F %%G IN %l_cbcon% DO (
if exist %dr_cb%\%%G (
copy %dr_cb%\%%G %drcb_O8322%\%%G

FOR /F %%G IN %l_cbcon% DO (
move %dr_cb%\%%G %drcb_O832T1%\%%G
goto :end1
move %dr_cb%\I* %drcb_O832T2%\
del /Q %dr_cb%

Report •

Related Solutions

Ask Question