4

I have a folder with a lot of folders with a lot of files and maybe more folders with more files, where some files lost their extension. I believe they are all jpgs, but I could be wrong. Any ideas how to re-add the extensions to all these files without doing it one by one?

I can do it on Windows 7 or Ubuntu 8.10.

6 Answers6

7

You can do it through cmd on windows.

rename * *.jpg


Edit:
To apply to nested folders, you can use;

for /r %x in (*) do rename "%x" *.jpg

RJFalconer
  • 10,369
3

I did it this way

find . -type f -iregex ".*[^\(\.jpg\)]" -exec mv "{}" "{}.jpg" ";"
2

If using powershell is an option, then this post from SO should be exactly what you want.

Jeffrey
  • 2,616
1

On Linux

ls | while read file ; do mv $file $file.jpg; done

On Windows

I like to use Rename4u which is a freeware utility.

djhowell
  • 3,801
0

Extension Renamer does the job.

ctzdev
  • 2,350
0

For Linux (or MSWindows w/CygWin)

If you wish to only add a suffix to files that are actually JPEGs, try this:

$ find . -type f  ! -name '*.jpg'  -print | while read f
> do case "$(file "$f")" in
>    *JPEG*) mv -iv "$f" "$f.jpg" ;;
>    esac
> done

Which will:

  1. Print paths that are files w/o a *.jpg suffix (find),
  2. Check those files' contents (file $f),
  3. For JPEG files, rename them with a _.jpg suffix.
NVRAM
  • 848