News:

2023-08-10 - ExifTool version 12.65 released

Main Menu

Undo Rename

Started by brandon, March 17, 2017, 04:08:39 PM

Previous topic - Next topic

brandon

Hello.  I just renamed some pictures using a cmd string I had used before (see below). For some reason, this time it changed the file name extension and now the files appear to be unusable. Is there any way to undo the naming and restore the files to a usable state? Thanks

exiftool -d %Y-%m-%d" "%H.%M.%S "-filename<${datetimeoriginal;}".":${subsectimeoriginal;$_.=0 x(3-length)}.%e"  -ext jpg .

StarGeek

Unfortunately, you can't undo a rename unless you specifically save the filename beforehand.

Luckily, it's easy to fix the lack of extension.
exiftool -ext * "-filename<%f.$fileTypeExtension" DIR
* 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).

StarGeek

Is this on Windows?  You have a colon in your filename which is an illegal character for Windows.  Everything from that point on is 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).

StarGeek

Upon further testing, the problem is more serious than I previously though.  Even though the file shows up in the directory, Windows is unable to access it, through gui and command line.  Even using wildcards doesn't help.

Edit: I just noticed that the filesize is 0 bytes.  Running CHKDSK didn't help, I'm unable to remove the file.
* 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).

brandon

Ok. Yeah. So looks like there is nothing I can do to recover the files, right?

StarGeek

Yeah, I think the file is gone.  I figured out how to remove the file, but couldn't figure out a way to get any data out of it, since windows doesn't think there is any data there. 

You might try a file recovery program, such as Recuva, but I wouldn't have much hope for that.

If you want to remove the empty files, you can use the command line and delete them using their 8dot3 filenames.  See this video.  The tl;dw version is
dir /x directory to get the 8.3 filename
del 8.3filename
* 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).

brandon

Ok. Thanks for the help. Are you able to tell what the exif tool command I used did to the file? As you state, windows thinks the file doesn't exist anymore.

StarGeek

#7
The command you posted has a colon : in it right before subsectimeoriginal.  The colon is an illegal character if it is anywhere except at the beginning for the drive designation.

Actually, wait.  Your files might be recoverable.  It looks like the colon treated your file as an NTFS Stream.  Let me test...

edit  Nope, I was wrong, sorry.
I tried dir /R directory to see what files had ADS (Alternate Data Stream) and the file didn't have one.  I then tried ADS Manager and it couldn't find anything either.
* 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).

brandon

Ok.  Thanks for the help and thanks for trying.

Phil Harvey

I don't know why this happens, but I have seen it before.  From this page:

Writing illegal file names in Windows can have unpredictable results and may result in data loss.

If someone can come up with a filter algorithm that catches filenames that are illegal in Windows, I can apply a Windows-specific check to ExifTool.

- Phil

Edit:  This page gives some useful information -- I'll study this in detail when I get a chance.
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

#10
OK, here is what I have so far.  I propose to add this code as a check before renaming any file in Windows:

    if ($^O eq 'MSWin32') {
        if ($newName =~ /[\0-\x1f<>"|*]/) {
            $self->Warn('New file name not allowed in Windows (contains reserved characters)');
            return -1;
        }
        if ($newName =~ /:/ and $newName !~ /^[A-Z]:[^:]*$/i) {
            $self->Warn("New file name not allowed in Windows (contains ':')");
            return -1;
        }
        if ($newName =~ /\?/ and $newName !~ m{^[\\/]{2}\?[\\/][^?]*$}) {
            $self->Warn("New file name not allowed in Windows (contains '?')");
            return -1;
        }
        if ($newName =~ m{(^|[\\/])(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.[^.]*)?$}i) {
            $self->Warn('New file name not allowed in Windows (reserved device name)');
            return -1;
        }
        if ($newName =~ /([. ])$/) {
            $self->Warn("New file name not recommended for Windows (ends with '$1')", 2) and return -1;
        }
        if (length $newName > 259 and $newName !~ /\?/) {
            $self->Warn('New file name not recommended for Windows (exceeds 260 chars)', 2) and return -1;
        }
    }


The last two warnings are minor, and may be ignored with the -m option.

If anyone has any comments about this I would be happy to hear them.

- Phil

Edit: Updated code to reflect what was released in ExifTool 10.47
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

More work to do.  Apparently a path starting with "\\?\" is legal -- I'll have to add support for this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Stephen Marsh

#12
I'm sorry to hear of your problem brandon. I know that this does not help you, however for any others out there that are new to ExifTool (or any other software for that matter)... Work on copies of the original files while testing, even more so for batches (even if using code that previously worked).


If you wish to copy the original filename before renaming files, I would use the Adobe Bridge tag that is supported by ExifTool:


Add/Copy filename to Adobe Preserve Original Filename (including file extension) metadata entry:

     exiftool -r '-XMP-xmpMM:PreservedFileName<${filename}' 'DIR-or-FILE'


Add/Copy filename to Adobe Preserve Original Filename (sans file extension) metadata entry:

     exiftool -r '-XMP-xmpMM:PreservedFileName<${filename;s/\.[^.]*$//}' 'DIR-or-FILE'


Rename/restore files using their preserved filename metadata entry:

     exiftool -r '-FileName<XMP-xmpMM:PreservedFileName' 'DIR-or-FILE'


(The above commands are formatted for the Mac OS, use double straight quotes " for Windows)