Is it possible to have ExifTool not automatically unhide Windows hidden files?

Started by mpegleg, May 26, 2019, 10:45:07 AM

Previous topic - Next topic

mpegleg

Hello.

I've searched the forum and FAQ for information on this issue, but wasn't able to find anything to solve my issue.

Whenever I use most ExifTool commands, (or GUI programs that make use of ExifTool), any Windows 10 files that have the "Hidden" attribute set, are changed to Unhidden status after the operations. [I generally use the -overwrite_original switch].

To keep things simple, I hide my original images (and any poor quality/uninteresting originals) in the same folder as my edits.

Via a resizer program, it only then sees the "unhidden" images, and thus only processes these particular images. Works perfectly for me.

So, what I wish for, is for ExifTool to leave any image files in the same Hidden/Unhidden state that they were in before they were processed. Is this at all possible? Is there an Exiftool switch that I'm not aware of, to enable this?

Note: I did write a short MSDOS batch file (to process multiple files via drag & drop) that did change the Hidden attribute back to it's original status after ExifTool was called, but I would much prefer to have ExifTool do this, so that any GUI programs will also leave hidden files as they were.

Thanks in advance.


[I'm using Windows 10 Pro with the Windows .exe version of ExifTool v11.44. I mainly use ExifMixer, or ExifTool GUI when I'm not using the command line directly].
OS: Windows 11 Pro

StarGeek

Try using the -overwrite_original_in_place option instead of -overwrite_original.

It's not my favorite option to use, as it does what it says and since I actually have had the power go out while using exiftool.  But I know it's been mentioned for use on the Mac to preserve some OS attributes that exiftool can't edit.

I'm also actually a bit surprised that the FileAttributes tag isn't editable.  My first thought was that it might be preserved by using "-FileAttributes<FileAttributes"

As an alternative, you could create a temp batch file to remember the files that are hidden before doing anything and then resetting them afterwards
exiftool >Temp.Bat -if "$FileAttributes=~/Hidden/" -p "attrib +h $FilePath" DIR
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mpegleg

Thanks for your reply StarGeek.

I tried using the -overwrite_original_in_place option, but unfortunately it made no difference, which was a surprise. I assumed that writing to the same file would not cause a change in the file's "hidden" attribute status, but I was wrong.

I was also hoping that the FileAttributes tag would be editable, but I'd already tried that, without success.

The batch file method is what I'm currently using. It works, but it's clunky.

Unfortunately, as I said previously, ExifTool also changes the status of hidden files after operations where it's used in GUI programs. Thus it's always an annoying two-step process, and I've been caught out with files that were previously hidden, suddenly re-appearing. I would have thought a hidden file should remain just that... a hidden file. :/



-------------
ps. By the way, for my simple purposes there's only "one" tag that I always need to modify, (and preferably "not" have ExifTool change the hidden attribute status of my photo images), and that is... -comment  (ie. JPEG Comment).

Thus, I use ExifTool simply to copy across the easily modifiable Windows -XPComment tag to the -comment tag, (which can then be accessed via my photo resizer program, for superimposing this particular tag info onto the edited version of each photo).

This is the Windows command-line I use, which works, but unfortunately always changes any jpeg file attribute from hidden to unhidden...
exiftool -m -overwrite_original "-XPComment>comment" FILE

OS: Windows 11 Pro

Phil Harvey

I have no idea why opening a file for rewrite should remove the hidden status in Windows.  I'll look into this when I get a chance (may be a while).

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

mpegleg

OS: Windows 11 Pro

StarGeek

I did some testing on this at the time and today it came back and bit me as I couldn't write to the text file I was playing with.  This may actually be a Windows command line thing.

I often redirect long exiftool output into a text file, appropriately named Temp.txt.  I added the hidden attribute to it and tested it with Notepad++, which would rewrite the file without problem and save the hidden bit.  But on the command line, you can't redirect into a hidden file.  It will fail (see second paragraph).  And when I tried -overwrite_original_in_place on a hidden image file, exiftool returned Error opening y:/!temp/Test4.jpg for writing.

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

This makes more sense.  I didn't understand how -overwrite_original_in_place could change the file attributes.  The fact that the open fails is weird, but at least understandable based on the reference you gave.

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

mpegleg

Quote from: Phil Harvey on May 27, 2019, 07:18:21 AM
I have no idea why opening a file for rewrite should remove the hidden status in Windows.  I'll look into this when I get a chance (may be a while).

- Phil

I acknowledge that response,

but just to confirm what I already suspect about this problem that I've got with ExifTool,
where it's un-hiding all of my previously hidden Windows image files, upon write operations.

I'm assuming that at present, it's "currently" not possible to use any kind of option or command with ExifTool to re-hide an image?

Am I correct in that assumption?

I don't understand why System -FilePermissions are Writable, but -FileAttributes are not?
     Win32::File::SetAttributes()?

I'm thinking that sure, it may not be possible to do any write operations on a "Hidden" file, but it should be possible to set the attributes on a new file copy?? No?

Most commonly the -FileAttributes option gives me the text:

"Regular; (none); Hidden, Archive" with a hidden image file,

and likewise:

"Regular; (none); Archive" when it's not hidden.


The only reason I'm asking, is that I was wondering whether (as a workaround for now) I could use the -FileAttributes option with some Regex code, to search for the "Hidden" text within this output string, (or even a binary match).

That would then allow me to use ExifTool to change the "Hidden" File Attribute of the actual image file back to "Hidden", after it has been written to by ExifTool.


So, what I'm effectively asking is... does ExifTool "currently" have the built-in capability to "modify" the status of the Hidden File Attribute (with Windows)?

I'm currently using the Windows MS-DOS attrib command in batch files to change the status back, but it would obviously be nicer/more efficient if ExifTool could do this itself.
OS: Windows 11 Pro

mpegleg

Hey, I just thought of a really easy way to perhaps achieve this.

Rename the output file as ".image.jpg" for example, and then immediately rename again back to the original filename.

When renaming a Windows file with a "." before the filename, it will always automatically force it into a "Hidden" state.

Problem solved. Too easy!


* EDIT: This is not a workaround fix that will work on standard Windows drives, only network drives. See following posts discussing this.
OS: Windows 11 Pro

obetz

Quote from: mpegleg on June 23, 2019, 12:19:21 PM
When renaming a Windows file with a "." before the filename, it will always automatically force it into a "Hidden" state.

Maybe other file managers or shells duplicate the unix dot file convention, but Explorer and command line "dir" of my Windows installations don't hide files starting with '.'.

BTW, I consider the Windows "hidden" attribute too fragile to use it as you are used to do.

mpegleg

Quote from: obetz on June 23, 2019, 01:23:33 PM
Maybe other file managers or shells duplicate the unix dot file convention, but Explorer and command line "dir" of my Windows installations don't hide files starting with '.'.

Ah. Of course. Trust me to be using this on my mapped network drive of my QNAP NAS. (ie. Unix based). lol. I didn't even think of that. (Windows does not hide files based on filename).

For my situation, my photos will always be on the NAS so it's an (almost) perfect fix for me, yet I realize now, that isn't going to help the majority of folks that don't use a NAS to store their photos. Oh well. It was my topic of concern, and it's solved my dilemma, so until they find a full solution, it'll do for me. :)


Quote
BTW, I consider the Windows "hidden" attribute too fragile to use it as you are used to do.

You are not wrong there! It "is" fragile, as I've learnt, but for my situation, with just regular family photos, luckily it's not really an issue, and as long as I have a fairly robust tag with the Hidden attribute stored, I can easily recover things.

I'll never go back to having separated "working" Originals and Edits in separate directories. That was an organizational nightmare for me. Having then together makes it so much easier for me to manage the editing process. (I do have multiple archive & backup copies of all of my originals).
OS: Windows 11 Pro

mpegleg

This code example, with the Copyright tag containing just "H":

-xpcomment="I am a new copied hidden file" execute -if "substr($Copyright,0,1) eq 'H' " -o "%d.%f.%e" -common_args -overwrite_original

gets my 'Hidden' "image.jpg" file processed, and renamed to ".image.jpg" (and thus is now also a "Hidden" file on my Unix based NAS mapped drive. It would "not" be Hidden on a standard Windows Drive).

Now, is there any way using ExifTool, to rename it back to the original filename? ie. image.jpg

Note: I don't want to be left with any extra files.

So close yet so far.  A measly "." away from solving my dilemma.

I'm of course worried that any ExifTool operation performed again, will simply "un-hide" the file all over again. :-\
OS: Windows 11 Pro

mpegleg

I really wish there was a test Regex generator like Regex101 in reverse? Does this exist?

For example, I could enter the base string="xyz", and it would give me the Regex code that would be needed to output just "yz".




Anyway, this will be very simple Regex for those that know, but I'm struggling to find it at the moment.

I just want the second character onwards returned.

ie. I have the string ".image.jpg", and I just want "image.jpg" returned. (ie. without the first ".")




Also, how do I use the value contained in xpcomment with the -o option?

eg).

I want this corrected:

-o "%d"$xpcomment

so that it will use the contents of xpcomment ("image.jpg") to complete the creation of the new filename.

At the moment, with my expression there, the $xpcomment is being treated as straight text, rather than using the "contents" of xpcomment.




Thanks,
-Paul
OS: Windows 11 Pro

Phil Harvey

With a substitution:

exiftool "-filename<${filename;s/^\.//}" ...

or with substr():

exiftool "-filename<${filename;$_=substr($_,1)}" ...

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

mpegleg

Thanks Phil. I can make use of both of those methods. Thanks for giving the alternate ways of doing it. That's always a great way of learning.

I'm going to relegate this issue to the too hard basket for the time being.

The problem is with the Windows OS, and how it doesn't like writing to Hidden files.

If you were able to find a way of remembering the original Hidden attribute status, and then re-applying it after all the ExifTool write operations, then that would be great.
OS: Windows 11 Pro