Find and Move File

June 7, 2010 at 17:36:45
Specs: Windows XP, 2.3 3G
I am trying to create a BATCH file that can automatically search a folder containing 100s of files, each file has a name like
(123456 Smith)
(789123 Brown)
And so on

I have a another folder containing 100s of sub folders each folder is named
(Smith, John)
(Brown, David)
And so on

I am trying to automate the process so a BAT file can scan the persons files and pick out the correct name and place it into the correct persons folder.

See More: Find and Move File

Report •

June 7, 2010 at 19:36:52
Is there just one Smith? One Brown?

Helping others achieve escape felicity


Report •

June 7, 2010 at 20:00:23
In the case of the Folders already created yes each destination folder is unique,

But in the case of the 100s of files there may be more than one, it would be ok if all similar files ended up in the same folder, for example.

(123456 Smith)
(453323 Smith)
(543321 Smith)

all end up under the folder
(Smith, John)

Report •

June 8, 2010 at 17:24:32
Perhaps if it is broken down into afew different commands,

Such as,
Make list of folder names
search files in directory for names containing X
Move File to folder named X

Repeat for each line in the list.

I am not sure if this is possible, but it would save me a great deal of time.

Report •

Related Solutions

June 8, 2010 at 20:17:21
@echo off & setlocal enabledelayedexpansion
pushd c:\work\test\files
for /f "tokens=1,2* delims=) " %%a in ('dir /b /a-d ^(*^).') do (
for /f "tokens=*" %%c in ('dir /b /ad c:\work\test\folders\"(%%b,*."') do (
::copy "%%a %%b)" "c:\work\test\folders\%%c"
echo copy "%%a %%b)" "c:\work\test\folders\%%c"
::----- end
remove the colons in front of line 6 if it looks ok.
add dbl-quotes as needed for those despicable spaces in
filesystem! !! !! !! (no further comment)

Report •

June 10, 2010 at 00:02:03
With my limited experence in programming i cannot make this script work.

Am i doing something wrong with it?

I placed all my files in c:\work\test\files
and all my folders in c:\work\test\folders

ran the BAT and nothing

Report •

June 10, 2010 at 00:12:40
can you give exact example of file and folder names?
ie: do they really have parentheses in them? like: "(a, b)"?
it ran ok on my test...

Report •

June 10, 2010 at 16:12:39
Thank you for your patience,

I have little experence with this programming,

The folders are in the 100-150 mark but each one is named
(C:\TestingFolders\Smith, John)
(C:\TestingFolders\Brown, David)
and so on.

The files are located in a seperate folder
(C:\TestingFiles\AAC951069 VOICEOVER - Smith NEW.msg)
(C:\TestingFiles\AAC234442 VOICEOVER - Brown NEW.msg)

I want the files to automatically move from TestingFiles into the correct Folder in TestingFolder.

Again thank you for your help with this it is very time consuming with the sheer amount of files I need to move.

Report •

June 10, 2010 at 18:56:38
modified to fix two percieved errors

@echo off & setlocal enabledelayedexpansion
pushd \testingfiles
for /f "tokens=1-5" %%a in ('dir /b /a-d *new.msg') do (
:: added an asterisk after var d.
for /f "tokens=*" %%z in
('dir /b /ad "c:\testingfolders\%%d,*"') do (
:: added a percent to var. e left off by acc.
echo copy "%%a %%b %%c %%d %%e" "c:\testingfolders\%%z"
::------- end
pls let me know what echos out. No files will be copied. testing only.

Report •

June 10, 2010 at 23:02:24
It echos

file not found
file not found
file not found
file not found

and will always close window automatically

I have to time a screenshot just to read what is in it.

if i turn echo on it echos back

C:\pushd \testingfiles

c:\testingfiles>for /F "tokens=1-5" %a in ('dir /b /a-d *new.msg') do (for /F "tokens=1" %z in ('dir /b /ad "c:\testingfolders\%d,"') do (echo copy %a %b %c %d \testingfolders\%z ) )

c:\testingfiles>for /F "tokens=1" %z in ('dir /b /ad "c:\testingfolders\Batson,"') do (echo copy AAC9594300 VOCIEOVER - Batson \testingfolders\%z ) )
File not found

Repeat for all files in the testingfiles directory

Report •

June 11, 2010 at 03:29:56
(sorry, my mistake):
change this line:
for /f "tokens=*" %%z in ('dir /b /ad "c:\testingfolders\%%d,"')
to this:
for /f "tokens=*" %%z in ('dir /b /ad "c:\testingfolders\%%d, %%e"')

thanks for the feedback, the echo info really helps!

Report •

June 11, 2010 at 05:02:44
I am still unable to achieve the desired effect,

with your additional line change it produced the same outcome as before with slight differences in the coding,

I can feel its really close and it would be such a shame to let your work go unfinished.

your response has already give me massive insight into what is going on, difficult to get correct and unfortunately outside my skill set but im trying to learn as much as i can.

Echo on

C:\pushd \testingfiles

c:\testingfiles>for /F "tokens=1-5" %a in ('dir /b /a-d *new.msg') do (for /F "tokens=*" %z in ('dir /b /ad "c:\testingfolders\%d, %e"') do (echo copy %a %b %c %d \testingfolders\%z ) )

c:\testingfiles>for /F "tokens=*" %z in ('dir /b /ad "c:\testingfolders\Batson, new.msg"') do (echo copy AAC9594300 VOCIEOVER - Batson \testingfolders\%z ) )
File not found

Repeats for every file inside the testingfiles directory

Report •

June 11, 2010 at 17:52:20
sorry again, my mistake again!
reload resp #8 and try.

Report •

June 11, 2010 at 22:56:30
I am sorry but i dont understand what (reload resp #8) is

Can you explain it to me?

Report •

Ask Question