0

I've used dbenham's excellent response to the question of how to add the folder name to the beginning of a filename in a cmd script.

@echo off
pushd "Folder"
for /d %%D in (*) do (
  for %%F in ("%%~D\*") do (
    for %%P in ("%%F\..") do (
      ren "%%F" "%%~nxP_%%~nxF"
    )
  )
)
popd

What I'm finding is that seemingly randomly (though it probably isn't) sometimes the script will run through several child folders and rename correctly but then it gets to a folder where it gets stuck in a loop and starts adding the folder name repeatedly to the file inside. I have 90,000 files in 300 folders to rename this weekend. Any chance you can guess the cause?

PS: Is there a maximum number of files that are acceptable in each folder?

  • might help to add a reference to the original question you are referring to. – Journeyman Geek Oct 19 '13 at 15:17
  • Maybe you have junction folders somewhere in your target directory. I [had a powershell script](http://superuser.com/questions/528487/list-all-files-and-dirs-without-recursion-with-junctions/528499#528499) to list all non-junction files/folders. Maybe you can tweak it to list only junctions. Otherwise I'll try it :) – nixda Oct 19 '13 at 15:25
  • I've opened up powershell (windows 7 pc) which I've never used before.... but I'm getting execution of scripts is disabled on my system. I can't disable it as my registry key is locked. :( – Flibble Wibble Oct 19 '13 at 15:33
  • If anyone has a simpler solution, I'm quite happy to go through each folder manually. I've just tried a forfiles solution but this has the same problem. – Flibble Wibble Oct 19 '13 at 15:49
  • nixda, assuming I have junction folders, what would I do about it? – Flibble Wibble Oct 19 '13 at 15:50

0 Answers0