1

I'm aware there's already questions like this but they either:

  • Throw errors that the file can't be found
  • Don't work or they uppercase instead

I'm unable to post comments in the other posted answers due to low reputation.

I don't mind, either, if it's .bat ran in the target directory or ran from the command line directly. I can only do basic stuff in MS-DOS.

So far I can set the directory I want:

x:
cd x:/folder1/folder2/target_folder

The result I want is this:

some_folder_in_target_folder/IMAGE1.jpg
some_folder_in_target_folder/Second/image1.JPG
some_folder_in_target_folder/Second/IMAGE2.JPG
some_folder_in_target_folder/Second/image3.jpg

to appear as:

some_folder_in_target_folder/image1.jpg
some_folder_in_target_folder/Second/image1.jpg
some_folder_in_target_folder/Second/image2.jpg
some_folder_in_target_folder/Second/image3.jpg

I don't want to modify the folder names themselves.

These files are on a USB drive. I don't know if that's causing some of the errors I saw from the other code samples I've tried.

Nalaurien
  • 948
  • 8
  • 13
Nova
  • 145
  • 1
  • 2
  • 8
  • 1
    If you did find working solutions that help you to uppercase the names change the part to make it uppercase to lowercase? What kind of code did you actually try and what errors where you getting? Why a batch and not a PowerShell script? – Seth Jun 12 '17 at 06:56
  • doing it in powershell would be much easier and faster – phuclv Jun 12 '17 at 08:08
  • I don't have any knowledge in PowerShell scripting. Also, I've read somewhere that scripts aren't portable due to Microsoft adding security to prevent malware or something. – Nova Jun 12 '17 at 18:12

1 Answers1

1

I disagree with Seth and Luru in this special case, there is a wonderful solution with a small flaw, this cmd line should remedy that (if the output looks right, remove the echo):

For /r X:\Path %A in (.) do @For /f "eol=: delims=" %F in ('dir /l/b/a-d "%A" 2^>NUL') do @Ren "%~fA\%F" "%F"

In a batch the % has to be doubled:

For /r X:\Path %%A in (.) do @for /f "eol=: delims=" %%F in (
  'dir /l/b/a-d "%%A" 2^>NUL'
) do Ren "%%~fA\%%F" "%%F"

The opposite, converting to uppercase would look clumsy in batch.

A powershell solution:

Get-ChildItem -Path X:\path -File|
  where-Object {$_.Name -cne $_.Name.ToLower()}|
    Rename-Item -NewName {$_.Name.ToLower()} -confirm

The same with aliases as a one liner:

gci -Path X:\path -File|? {$_.Name -cne $_.Name.ToLower()}|Ren -new {$_.Name.ToLower()} -confirm
LotPings
  • 7,011
  • 1
  • 15
  • 29
  • None of them seemed to work. The MS-DOS ones prints list of all the files of the tree but doesn't perform any alteration from the files that are in uppercase. I removed the `@echo` part leaving just a space between `do` and `ren` in second attempt I presume I what I had to do. PowerShell accepted the commands but didn't do anything at all. I've replaced `X:\Path` with the target folder. The link solution is one of them I tried before asking, it throws "File Not Found" when I ran it in the correct cd directory. – Nova Jun 12 '17 at 17:46
  • My own tests just now did work for all 4 variants. My last edit only removed the echos. The current folder doesn't matter, just the given path to start with instead of X:\path (maybe a single `.` (dot) for the current folder). – LotPings Jun 12 '17 at 18:17
  • I tried the modified first one and it still didn't work for me. I even tried `For /r . %A in (.) do @For /f "eol=: delims=" %F in ('dir /l/b/a-d "%A" 2^>NUL') do @Ren "%~fA\%F" "%F"` in the correct cd directory. I can see the title flashing file names while the process is running. I'm on my Windows Administrator account. Can installing "Bash on Ubuntu on Windows" break MS-DOS? The drive I'm using is a Fat32 file system USB if that causing any issue. – Nova Jun 12 '17 at 18:38
  • It **IS** an issue with Fat32. I've WSL running myself, so that isn't the reason. Just created a Ramdisk with FAT32 for my testing. Even temporarily renaming to a different extension didn't help. Is the USB drive a test environment or your target? – LotPings Jun 12 '17 at 20:56
  • It's the target but I have a backup I sync to so I can undo the changes. – Nova Jun 12 '17 at 21:04