0

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?

888123AA.pdf  
888123BB.pdf  
888123CC.pdf  
777456AA.pdf  
777456BB.pdf  
777456CC.pdf 

Default folder:

999-888123-03
666-777456-01
user2389248
  • 29
  • 1
  • 8

2 Answers2

1
@echo off
setlocal EnableDelayedExpansion

rem Process all .pdf files
for %%a in (*.pdf) do (
   rem Get just the file name, ie: "888123AA"
   set fileName=%%~Na
   rem Using the file name minus two last chars, ie: "888123"
   rem get the default folder with that name
   for /D %%b in (*-!fileName:~0,-2!-*) do (
      rem And copy the file to that folder
      copy "%%a" "%%b"
   )
)
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • any idea and advice of below: The following usage of the path operator in batch-parameter substitution is invalid: %~Na For valid formats type CALL /? or FOR /? The syntax of the command is incorrect. – user2389248 Jun 06 '13 at 11:17
-1

I don't remember any apparent way to do it other than a UNIX shell... Maybe get MSYS and use that (outdated) bash to help?

Here is a bash script that can use after you installed bash from MSYS (or you can sort it with a Linux box - Ubuntu is no bigger than 800MB and can run as LiveCD without interfering your current Windows system, and the LiveCD can double as a system saver when needed. :-)

#!/bin/bash
for each in ./*; do
    if [ -d $each ]; then # Only folders are minded.
        # Extract the second part of the folder name.
        ACCOUNT_NAME=`echo $each | sed "s/\\-/\n/" | head -n 2 | tail -n 1`
        cp -v ./$ACCOUNT_NAME*.pdf $each
    fi
done
Maxthon Chan
  • 1,181
  • 8
  • 15