Jon Osborn
2008-05-19 17:46:03 UTC
We have a program creates reports for each of our offices. The files are
always named *_location.m2t where the * is a always random characters. We
would like to be able to sort the files in to different Directorys.
Here are some excate Eamples
The Folder D:\Contents\Cherrypick_test has these files
Job-01C8A968-8CB4110A_CurTMGPCD Jonesboro.m2t
Job-01C8A969-546C46C2_CurTMGPCD Little Rock.m2t
Job-01C8A96F-4A222142_CurTMGPCP Dallas.m2t
Job-01C8A96F-D0AE056A_CurTMGPCP Houston.m2t
Job-01C8A970-290AE2EA_CurTMGPCP Jonesboro.m2t
Job-01C8A970-E8E940DA_CurTMGPCPLittleRock.m2t
Job-01C8A9FC-AEE0937E_CurTMGPCP Memphis.m2t
Job-01C8A9FF-4F976F6A_CurTMGPCP Texarkana.m2t
Job-01C8AA02-FC4EF59A_CurTQGPCP Authorized Resellers.m2t
Job-01C8AA07-BA24389A_CurTQGPCP General Resellers.m2t
And we want the files sorted into these folders
D:\contents\Jonesboro
D:\contents\Little Rock
D:\contents\Dallas
D:\contents\Houston
D:\contents\memphis
D:\contents\Authorized
D:\contents\General
And the if location is not there move it into the D:\contents\lost_and_found
folder ( I now the lost and found will have to be the last command run)
_______________________________________________________
I found a script (in this newsgroup) that will sort file if a specific text
is in the file (below) and I like how it works but if could be modified to
work on files names it would be perfect. If figure I could change the Set
String line and do a different loop for each location. I am sure the boss
is going to add more to it once it starts to work. I know enough about
batching to create a simple ones or modify some batches. I figure there is
a different command other than find for file names but I am not sure what.
Again if this could be modifled to work with filenames it would be perfect
for us. Of course these are just test Directorys so I will change them to
production once we get the script working. I know the lost and found part
will not work, but I can cut that out and run it as the last command.
@echo off
setlocal enabledelayedexpansion
set string=Dallas
set source=D:\Contents\Cherrypick_test
set target1= D:\contents\lost_and_found folder
set target2=D:\Contents\Cherrypick_test\Dalls
REM if not exist "%target1%" md "%target1%"
REM if not exist "%target2%" md "%target2%"
for %%a in ("%source%\*.m2t") do (
set target=%target2%
find /i "%string%" "%%a" nul && set target=%target1%
echo move "%%a" "!target!"
)
set string=Jonesboro
set source=D:\Contents\Cherrypick_test
set target1= D:\contents\lost_and_found folder
set target2=D:\Contents\Cherrypick_test\Jonesboro
for %%a in ("%source%\*.m2t") do (
set target=%target2%
find /i "%string%" "%%a" nul && set target=%target1%
echo move "%%a" "!target!"
)
Thanks for any help
Jon
always named *_location.m2t where the * is a always random characters. We
would like to be able to sort the files in to different Directorys.
Here are some excate Eamples
The Folder D:\Contents\Cherrypick_test has these files
Job-01C8A968-8CB4110A_CurTMGPCD Jonesboro.m2t
Job-01C8A969-546C46C2_CurTMGPCD Little Rock.m2t
Job-01C8A96F-4A222142_CurTMGPCP Dallas.m2t
Job-01C8A96F-D0AE056A_CurTMGPCP Houston.m2t
Job-01C8A970-290AE2EA_CurTMGPCP Jonesboro.m2t
Job-01C8A970-E8E940DA_CurTMGPCPLittleRock.m2t
Job-01C8A9FC-AEE0937E_CurTMGPCP Memphis.m2t
Job-01C8A9FF-4F976F6A_CurTMGPCP Texarkana.m2t
Job-01C8AA02-FC4EF59A_CurTQGPCP Authorized Resellers.m2t
Job-01C8AA07-BA24389A_CurTQGPCP General Resellers.m2t
And we want the files sorted into these folders
D:\contents\Jonesboro
D:\contents\Little Rock
D:\contents\Dallas
D:\contents\Houston
D:\contents\memphis
D:\contents\Authorized
D:\contents\General
And the if location is not there move it into the D:\contents\lost_and_found
folder ( I now the lost and found will have to be the last command run)
_______________________________________________________
I found a script (in this newsgroup) that will sort file if a specific text
is in the file (below) and I like how it works but if could be modified to
work on files names it would be perfect. If figure I could change the Set
String line and do a different loop for each location. I am sure the boss
is going to add more to it once it starts to work. I know enough about
batching to create a simple ones or modify some batches. I figure there is
a different command other than find for file names but I am not sure what.
Again if this could be modifled to work with filenames it would be perfect
for us. Of course these are just test Directorys so I will change them to
production once we get the script working. I know the lost and found part
will not work, but I can cut that out and run it as the last command.
@echo off
setlocal enabledelayedexpansion
set string=Dallas
set source=D:\Contents\Cherrypick_test
set target1= D:\contents\lost_and_found folder
set target2=D:\Contents\Cherrypick_test\Dalls
REM if not exist "%target1%" md "%target1%"
REM if not exist "%target2%" md "%target2%"
for %%a in ("%source%\*.m2t") do (
set target=%target2%
find /i "%string%" "%%a" nul && set target=%target1%
echo move "%%a" "!target!"
)
set string=Jonesboro
set source=D:\Contents\Cherrypick_test
set target1= D:\contents\lost_and_found folder
set target2=D:\Contents\Cherrypick_test\Jonesboro
for %%a in ("%source%\*.m2t") do (
set target=%target2%
find /i "%string%" "%%a" nul && set target=%target1%
echo move "%%a" "!target!"
)
Thanks for any help
Jon