I have a directory structure as below:
Folder
> FileName1.abc
> Filename2.abc
> .............
Folder2
> FileName11.abc
> Filename12.abc
> ..............
> ..........
etc. I have a command that can prepend folder names to filenames.
Sample:
Folder1_Filename1.abc
Folder1_Filename2.abc
I want to change it like this.
Make the folder name the same as the file names:
Folder1.abc
Folder1 (1).abc
Folder2.xyz
Folder2 (1).xyz
i.e. As a result I want to replace the filenames with the folder name. If there are files with different names with the same extension, they can add (1), (2) to the end of the names.
Script:
@echo off
pushd "Folder"
for /d %%D in (*) do (
pushd "%%D"
for /r %%F in (*) do (
for %%P in ("%%F\..") do (
ren "%%F" "%%~nxP_%%~nxF"
)
)
popd
)
popd
The above command doesn't do what I want.
This command just adds the folder name to the beginning of the filenames.
PS: I changed the command "%%~nxP_%%~nxF"
to "%%~nxP%%~xF"
command.
And I have almost completed what I wanted.
But at one point I saw that only 1 of the files with the same extension changed their name.
I've been looking for a command that can add (1), (2), (3) when saving the names of files with the same extension; but I couldn't find it.
Detailed example:
Folder
> Folder.jpg
> Folder (1).jpg
> Folder (2).jpg
> .............
I would be grateful if you know of a command that can do what I want other than the above command.
You deserve appreciation.