Computing.Net > Forums > Programming > Batch Move Files From [list1] to [list2]

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.

Batch Move Files From [list1] to [list2]

Reply to Message Icon

Name: transoniq
Date: May 21, 2009 at 11:08:27 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Here's a little batch I've been using to move files with full paths specified in a txt list (filelist.txt) to a folder called "files" on the C drive:

@echo off
for /F "delims=" %%i in (filelist.txt) do (
echo %%i
move "%%i" c:\files
)

The source files listed in filelist.txt are scattered throughout a dir on an external drive that has a large and complex subdir tree, but when this batch is run, everything is moved to a single, flat c:\files dir. It's great for what it does, but one problem is that if there are any duplicate file names in filelist.txt, the batch will overwrite any previously moved 1.doc (for example) with a 1.doc further down the list.

Anyone know how to tweak this bat so that instead of moving everything to the single c:\files dir, it will--as needed--replicate the dir structure on the destination drive as it moves the files? This will prevent the overwrites, of course, but it will also be useful to have the "cloned" dir structure from the external drive under the destination dir (not the entire tree, but just the dirs/subdirs that actually contain moved files specified in filelist.txt!).



Sponsored Link
Ads by Google

Response Number 1
Name: transoniq
Date: May 24, 2009 at 09:13:06 Pacific
Reply:

Figured it out. In case anyone else is having a similar problem, I added a "destination path" column (tab delimited) to filelist.txt to the right of the "source files" column and populated it with the source file path with just the drive letter replaced. Token 1 (variable %%i) = the file (with path) to move, and token 2 (variable %%j) = the destination directory.

I could've added an ifexists to the md command so that it doesn't try to create the same dir more than once, but the batch continues to run on an "already exists" error, so that's not necessary. Also important: replace the "<tab>" in the code below with an actual tab in the text .bat file.

@echo off
for /F "tokens=1,2 delims=<tab>" %%i in (filelist.txt) do (
md "%%j"
echo %%i
move "%%i" "%%j"
)


0
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: Batch Move Files From [list1] to [list2]

move files from client to network s www.computing.net/answers/programming/move-files-from-client-to-network-s/18745.html

batch move files log help www.computing.net/answers/programming/batch-move-files-log-help/16877.html

Moving Files one at a time www.computing.net/answers/programming/moving-files-one-at-a-time/11177.html