Restore file extensions

Started by ilovelinux, January 23, 2020, 04:43:13 AM

Previous topic - Next topic

ilovelinux

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

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

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

greybeard

Very good - much better solution - when single quotes are required then the * will need double quotes "*"

ilovelinux

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

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

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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

ilovelinux

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

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

Quote from: ilovelinux on January 24, 2020, 04:03:37 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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).