Well, there’s several things happening:
- Is your system set up to use a language other than English?
On my (English-based) system,
the command that you are trying to do is
FOR /F, not FOR /G.
- You’re extracting three (
1-3) tokens starting with %%G,
but then you’re using %%F, %%G, and %%H.
Nothing is being put into %%F.
Either change the FOR statement to refer to %%F,
or change the loop body to use %%G, %%H, and %%I.
Except …
… don’t do that.
Your approach is flawed.
Think about what it means to have period (.) and space as delimiters.
Your filenames get broken into tokens like this:
#1 #2 #3 #4 #5
ERJP00300029 3.13.jpg → ERJP00300029 3 13 jpg
SRKP00100002 12.04.jpg → SRKP00100002 12 04 jpg
ERJP01500001 ERJP12 10.5.jpg → ERJP01500001 ERJP12 10 5 jpg
so,
- the filename is not always equal to
part1 part2.part3,
- the extension not always the third token, and, in fact,
- for your example filenames, it’s never the third token, and
- it isn’t always the same token number.
We’ll have to get back to this.
- What do you think you’re doing with the REN (RENAME) command?
Specifically,
why are you putting
\%SourceDir% between part1 and part2?
The only hope you have of making this work
is to put %SourceDir%\ before part1.
And note that the backslash (\) needs to come after %SourceDir%.
- If this is the complete batch file,
you don’t need to do anything special at the end.
The batch file will exit when it reaches the end.
But, if this is part of a larger system,
you might want to have an explicit terminating command at the end.
That command should be
GOTO :EOF, not GOTO EOF.
Not to pile on, but your approach of taking the output from DIR
and immediately breaking it down in tokens is flawed.
Looking at your example names,
the string ERJP12 10.5 gets broken down into three tokens:
ERJP12, 10, and 5.
But ERJP12.10.5 would get broken down into the same tokens,
and so would ERJP12 10 5 and ERJP12.10 5.
You can’t reconstruct the original (i.e., current, existing) filenames
from the tokens;
you need to capture the original filename intact, and then break it down.
I don’t see why you need to run DIR.
All you need is FOR %%F IN ("%SourceDir%\*.jpg") DO;
it will give you the names of files only (no subdirectories),
and, unlike the output of DIR,
it will include the name of the source directory
(the directory that contains the files).
Now that we have the complete current file pathname in %%F,
we can start to break it down.
Now we use FOR /F.
So, take the file name portion of %%F,
and pull out a token that is the first part alone.
Then rename the original full pathname
to the first part plus the extension.
Here’s the complete batch file:
SET SourceDir=F:\Ezhilarasan\Exibt\need_upload\ERHP\check
FOR %%F IN ("%SourceDir%\*.jpg") DO (
FOR /F "DELIMS=. " %%A IN ("%%~nF") DO (
REN "%%F" "%%A%%~xF"
)
)