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
    What is your Operating System? Scripting language? As it stand your question is impossible to answer. Also, please note that Super User is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?. – DavidPostill Sep 4 '16 at 7:27
  • 1
    @DavidPostill At first look, I thought he meant batch as in "batch programming in Windows" as the tags of the question were command-line and batch, but on further reading, he has mentioned the mv command, which means he is talking about Unix/Linux. – Don't Root here plz... Sep 4 '16 at 13:34
  • Have you tried just using the files as-is. Some software doesn't care about multiple extensions and uses the last one. – fixer1234 Sep 5 '16 at 4:17
1

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.