# Batch file for copy many files to many folders?



## TAHERKHANI (Dec 7, 2012)

hi everyone,

i have many folders like this:
"5002.1 persian"
"6001 russian"
"6014.1 english"
.
.
.
and have files like this:

C:\books\000-C5002-1.pdf
C:\books\001-030-C5002-1.pdf
C:\books\031-067-C5002-1.pdf
C:\books\068-093-C5002-1.pdf
C:\books\094-135-C5002-1.pdf
C:\books\136-167-C5002-1.pdf
C:\books\168-205-C5002-1.pdf
C:\books\206-243-C5002-1.pdf
C:\books\244-283-C5002-1.pdf
C:\books\284-312-C5002-1.pdf

C:\books\000-C6001.pdf
C:\books\001-022-C6001.pdf
C:\books\023-046-C6001.pdf
C:\books\047-081-C6001.pdf
C:\books\082-105-C6001.pdf
C:\books\106-170-C6001.pdf

C:\books\000-6014-1.pdf
C:\books\032-066-6014-1.pdf
C:\books\067-095-6014-1.pdf
C:\books\096-134-6014-1.pdf
C:\books\135-147-6014-1.pdf
C:\books\148-181-6014-1.pdf
C:\books\001-031-6014-1.pdf
.
.
.

I want a bach file for copy files to those folders.

I test this code, but not work:

*move *5002-1.pdf 5002.1*
move *6001.pdf 6001*
move *6014-1.pdf 6014.1**

thanks for your help.


----------



## foxidrive (Oct 20, 2012)

You haven't explain how the names are parsed.

What you can do is use a little bit of manual editing and then the script will sort the bulk of the files easily.


```
@echo off
for %%a in (
5002-1
6001
6014-1
) do (
md "%%a" 2>nul
for %%b in ("*%%a.pdf) do move "%%b" "%%a"
)
pause
```


----------



## TAHERKHANI (Dec 7, 2012)

foxidrive said:


> You haven't explain how the names are parsed.
> 
> What you can do is use a little bit of manual editing and then the script will sort the bulk of the files easily.
> 
> ...


thanks, but not work.

I want the files that has the same number in it's names to be moved to the folders that has the same number.


----------



## TAHERKHANI (Dec 7, 2012)

foxidrive said:


> You haven't explain how the names are parsed.
> 
> What you can do is use a little bit of manual editing and then the script will sort the bulk of the files easily.
> 
> ...


Some folders have unicode character, i mean i have folder like "4002.1 عربی"


----------



## foxidrive (Oct 20, 2012)

Try a group for VBS scripts. Batch files don't handle unicode very well.


----------



## foxidrive (Oct 20, 2012)

Test this on sample files and folders first.


```
@echo off
(
echo Dim strPath
echo Set oFSO = CreateObject^("Scripting.FileSystemObject"^)
echo strPath = "%cd%"
echo DoStuff oFSO.GetFolder^(strPath^).Path
echo Sub DoStuff^(sDir^)

echo Set oDir = oFSO.GetFolder^(sDir^)


echo For Each a In oDir.Files
echo v=right(a.name,10^)
echo v=left(v,6^)
echo if left(v,1^) = "-" then v=mid(v,2^)
echo if mid(v,4,1^) = "-" then v=left(v,3^)+"."+mid(v,5^)
echo if mid(v,5,1^) = "-" then v=left(v,4^)+"."+mid(v,6^)
echo if mid(v,2,1^) = "-" then v=mid(v,3^)
echo if mid(v,3,1^) = "-" then v=mid(v,4^)
echo wscript.echo v
echo For Each i In oDir.SubFolders
echo w=left(i.name,len(v^)^) + " "
echo if w = v + " " then ofso.movefile a.name, i.name + "\"
echo Next
echo Next

echo End Sub
)>"%temp%\vbsfiledate.vbs"

cscript /nologo "%temp%\vbsfiledate.vbs"
:copy "%temp%\vbsfiledate.vbs" .
del "%temp%\vbsfiledate.vbs"
pause
goto :EOF
```


----------

