1

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
Raptor
  • 53,206
  • 45
  • 230
  • 366
user2389248
  • 29
  • 1
  • 8

1 Answers1

0
@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"
   )
)
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • If _all folders_ are located in the same drive (different than file's drive), just insert it in the willd-card (name) of target folder. If each target folder may be located in a different drive, use the first version with full folder names. – Aacini May 28 '13 at 11:19