Computing.Net > Forums > Programming > Move the first file in a folder

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Move the first file in a folder

Reply to Message Icon

Name: dolly
Date: May 13, 2009 at 15:38:12 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi

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
I1.txt
I2.txt
I3.txt
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.
Thanks
Dolly



Sponsored Link
Ads by Google

Response Number 1
Name: Valerie (by Garibaldi)
Date: May 13, 2009 at 19:13:05 Pacific
Reply:

Here's one way, change copy to move when you're finished testing:

@echo off
cls

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


0

Response Number 2
Name: Mechanix2Go
Date: May 14, 2009 at 10:46:50 Pacific
Reply:

Depends on how you define first.


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

M2


0

Response Number 3
Name: dolly
Date: May 14, 2009 at 12:21:44 Pacific
Reply:

Hi

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 ..
@ECHO ON
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
)
:end1
move %dr_cb%\I* %drcb_O832T2%\
del /Q %dr_cb%


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Move the first file in a folder

zip all the .csv files in a folder www.computing.net/answers/programming/zip-all-the-csv-files-in-a-folder/16724.html

.BAT To use FTP and find first file in folder www.computing.net/answers/programming/bat-to-use-ftp-and-find-first-file-in-folder/19566.html

Unzip All the Zip files from a folder www.computing.net/answers/programming/unzip-all-the-zip-files-from-a-folder/20244.html