Author Topic: Restore file extensions  (Read 167 times)

ilovelinux

  • Newbie
  • *
  • Posts: 4
Restore file extensions
« on: January 23, 2020, 04:43:13 AM »
Hello dear community, I hope I'm in the right area of this forum.
I have the following problem:

When backing up with luckybackup from a Windows / Mac external hard drive, all file extensions were removed.  :-\

Problem: Windows and Mac can no longer read these files.  :'(

I would now like to add the extension to all files again without copying the file.
I just want to rename the files.

Folder structure: / media / portable / Leopoldine2 / files

In the files folder there are 62 folders with about 5000 files each and 10 different file types.

My English is not very good, I do not understand the description of the individual commands very well.

I hope someone can tell me what command I have to do?

Thanks in advance

greybeard

  • Sr. Member
  • ****
  • Posts: 100
Re: Restore file extensions
« Reply #1 on: January 23, 2020, 05:31:14 AM »
I'm assuming from your user name that this is Linux?

Does the Linux "file --mime-type" command identify the files and can you supply extensions that go with the mime-types?

I'm not sure you need exiftool to do this (but maybe I'm wrong and there is a much better way to do it and I'm sure someone will correct me)

Something like this would add the "jpg" extension for files with a mime type of "image/jpeg".

find . -type f ! -name "*.*" | while read FILE; do if [[ -n `file --mime-type "$FILE" | grep 'image/jpeg'` ]]; then mv "$FILE" "$FILE".jpg; fi; done;

(As usual test thoroughly and backup everything before you run against your files)

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3129
Re: Restore file extensions
« Reply #2 on: January 23, 2020, 11:42:13 AM »
To do this with exiftool, try this
exiftool -r -ext * "-Filename<%f.$FileTypeExtension" <DIR>

This will go through the target directory and all sub-directories and add an extension to any file it can identify.

If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

greybeard

  • Sr. Member
  • ****
  • Posts: 100
Re: Restore file extensions
« Reply #3 on: January 23, 2020, 12:29:58 PM »
Very good - much better solution - when single quotes are required then the * will need double quotes "*"

ilovelinux

  • Newbie
  • *
  • Posts: 4
Re: Restore file extensions
« Reply #4 on: January 23, 2020, 01:14:44 PM »
Thank you for the fast answer.
Yes, I use Linux Ubuntu 18.4
But the command you wrote me down does not work.
I get the following error message:
  Syntax error in the unexpected word "newline"

greybeard

  • Sr. Member
  • ****
  • Posts: 100
Re: Restore file extensions
« Reply #5 on: January 23, 2020, 01:45:26 PM »
You need to replace <DIR> by the actual directory name - if you run the command in the same directory as the files then you would use a point .

exiftool -r -ext * "-Filename<%f.$FileTypeExtension"  .

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3129
Re: Restore file extensions
« Reply #6 on: January 23, 2020, 02:12:40 PM »
Also, as I said, you have to reverse any double/single quotes under Mac/Linux.  Adding in what greybeard said about the asterisk, you should run this as your command.  Replace <DIR> with the path to the directory you want to process.  Use a dot . to indicate the current directory.
exiftool -r -ext "*" '-Filename<%f.$FileTypeExtension' <DIR>

Additionally, the second image you posted shows that all those files have 0 bytes.  There's nothing in those files to add an extension to.  Whatever the original files were, they're lost.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

ilovelinux

  • Newbie
  • *
  • Posts: 4
Re: Restore file extensions
« Reply #7 on: January 23, 2020, 03:19:40 PM »
OK
exiftool is now working.

as far as I can see it does everything right.
he does not recognize a few mac files but that is not a problem.

with so many dates it will take a few hours.
I will get in touch tomorrow and announce the result.

ilovelinux

  • Newbie
  • *
  • Posts: 4
Re: Restore file extensions
« Reply #8 on: January 24, 2020, 04:03:37 AM »
it's a Dream

Everything worked great!

There were:
320980 files updated
173 files remained unchanged (these were already correctly labeled)
25490 files were not updated due to errors

This result is amazing !!

Many many thanks!

I still have a question.
All file names have been renamed by a strange recovery program.
Is there a way to restore this file name?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3129
Re: Restore file extensions
« Reply #9 on: January 24, 2020, 10:36:00 AM »
I still have a question.
All file names have been renamed by a strange recovery program.
Is there a way to restore this file name?

Unlikely.  Filenames are kept in the an index.  For example, for Windows NTFS you can look at the Wikipedia Master File Table entry for details.  Usually when recovering files, that data is gone.

The only way to recover filenames would be either
1) You planned ahead and somehow had those names embedded in the files.
2) You could reconstruct the filename from data in the file.  The would depend upon your naming system.  For example, a lot of people use a YEAR-MONTH-DAY-HOUR-MINUTE-SECOND format for images and videos and that could be reconstructed easily.  Similarly, for music files, people usually put in data such as song names, artist, album, etc.

Files such as databases and executables don't have such data in the files and would have to be examined individually.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.