Reputation: 21
I have a batch script that moves .eps
and .pdf
files into separate folder with .eps
in Highres
, and .pdf
in Lowres
. But I want to name the main folder as the file name.
For instance, if I am copying Man.eps
and Man.pdf
, the respective main folder name should be Man
and inside that, Man.eps
should be in Highres
subfolder, and Man.pdf
should be in Lowres
subfolder.
Here is what I have come so far:
@echo off & setlocal
> nul mkdir "%%~pA"
for %%F in (*.eps) do (
> nul mkdir "%%~pA/HIGHRES"
> nul move "%%F" "%%~pA/HIGHRES"
for %%F in (*.pdf) do (
> nul mkdir "%%~pA/LOWRES"
> nul move "%%F" "%%~pA/LOWRES"
)
)
It creates folder name with %%~pA
, I just want the file name to be used as the folder name...
Upvotes: 1
Views: 60
Reputation: 3452
There are a couple of things wrong with your code. When using for to loop through a fileset, you should use for /R
. Furthermore, %%~pA
tries to get part of a variable named %%A
, which you don't have. Also, you shouldn't forget to close your first for loop. Finally, you should use ~n
and ~nx
to get filename or filename+extension respectively.
Try this:
@echo off
for /R %%F in (*.eps) do (
mkdir "%%~nF/HIGHRES"
move "%%F" "%%~nF/HIGHRES/%%~nxF"
)
for /R %%F in (*.pdf) do (
mkdir "%%~nF/LOWRES"
move "%%F" "%%~nF/LOWRES/%%~nxF"
)
Upvotes: 2