Link to home
Start Free TrialLog in
Avatar of Chris Lopez
Chris Lopez

asked on

Fix Error Of Duplicate Folders When Renaming Folders

script I use

@echo off
setlocal enabledelayedexpansion

pushd "c:\temp"

for /D %%F in (*) do (
  set fn=%%~nF
  ren "%%~F" "!fn:~0,-4!
)

Open in new window



I had this question after viewing Remove last few characters of a folder name.

Okay I found this script does what I want but the Issue I have is that with folders that will end up with the same name I wish to Merge them and if their is content inside these folders that are the same than its OK overwrite them aswell.



So Say

Folder 1
 --dog.txt
 --cat.mp4
 --pool.jpg

folder 2
--cat.mp4
--honey.mp4
--car.mp4

so the merge result will be

folder
--dog.txt
--cat.mp4
--pool.jpg
--honey.mp4
--car.mp4


I am on windows 10 if that matters.
Avatar of NVIT
NVIT
Flag of United States of America image

- Save this as a .bat file.
- Open a CMD window
- Run the bat
- If it looks correct, remove the ECHO words to run it for real.

@echo off
setlocal enabledelayedexpansion

pushd "c:\temp"

for /D %%F in (*) do (
  set fn=%%~nF
  if exist "!fn:~0,-4!\*."
    ECHO copy /y "%%~F" "!fn:~0,-4!"
  ) else (
    ECHO ren "%%~F" "!fn:~0,-4!"
  )
)

Open in new window

Avatar of Bill Prew
Bill Prew

Are there just files under each folder you are processing, or could there be subfolders as well?

~bp
Avatar of Chris Lopez

ASKER

NVIT,

That didnt seems to work

-

BP,

It will just be file's in the folders no sub directories.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial