Question

I would like to use a batch file to put them into default folder, but the account name is in the middle of the folder. Have any script I can use in dos command prompt?

888123_AAAA_20130313.pdf  
888123_BBBB_20130313 (2).pdf  
888123_CCCC_20130313_2.pdf  
777456_AAAA_20130313.pdf  
777456_BBBB_20130313 (2).pdf  
777456_CCCC_20130313_2.pdf  

Default folder:

999-888123-03
666-777456-01
Was it helpful?

Solution

@echo off
setlocal EnableDelayedExpansion

rem Create the list of default folders
set folder[888123]=999-888123-03
set folder[777456]=666-777456-01

rem Copy the files
for /F "tokens=1* delims=_" %%a in ('dir /B /A-D *.pdf') do (
    copy "%%a_%%b" "!folder[%%a]!"
)

EDIT: The version below don't need to initialize the list of default folders:

@echo off
for /F "tokens=1* delims=_" %%a in ('dir /B /A-D *.pdf') do (
   for /D %%d in (*_%%a_*) do (
      copy "%%a_%%b" "%%d"
   )
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top