0

I have multiple files named ".txt.jpg" (don't ask...) in a single directory. I would like to remove the ".txt" portion so the result becomes ".jpg" only so I can then import them into Photos.

Any suggestions? I looked at previous Q/A involving the mv command but couldn't quite figure out how to write the correct command. I don't want to mess further. Thanks

1 Answers1

3

If you are on Windows, and if there are no additional dots in any of the file names, then you can use the following:

ren *.txt.jpg ???????????????????????????????????????????????????.jpg

There must be enough ? to match the length of the longest file name. See How does the Windows RENAME command interpret wildcards? for more info.

If some files have more than two dots, then you will need more than a simple REN command. The following should remove the unwanted .txt regardless how many dots are in the original name.

for %A in (*.txt.jpg) do @for %B in ("%~nA") do @ren "%A" "%~nB.jpg"

If you put the command within a batch script then you must double the percents:

@echo off
for %%A in (*.txt.jpg) do for %%B in ("%%~nA") do ren "%%A" "%%~nB.jpg"
dbenham
  • 11,794