Link to home
Start Free TrialLog in
Avatar of xenium
xenium

asked on

edit and retrieve file attribute info using dos command

hi,

I'd like to be able to extract comment info from some jpg files using a dos command in a  batch file, and also be able to update comment info. Is there a way?

I'm using Windows 10

Thanks
Avatar of Ganesh Anand
Ganesh Anand
Flag of Bahrain image

I am not sure if that works easily but i have an utility which helps a lot. It is free opensource called BulkFileChanger. It can edit attribute of file and export.

http://www.nirsoft.net/utils/bulk_file_changer.html
Dos? Is vbscript/powershell one of the options?

is the comment within the jpg data,
For This you have to use a tiny utility known as jhead.

http://www.sentex.net/~mwandel/jhead/

Copy the jhead.exe to C:\MassComment\   (Create a folder named "masscomment")

Here are the command line which you can use:


TO ADD A COMMENT :
Go to C:\MassComment within command line and run :

jhead -cl your_comment_here C:\Mypictures\*.jpg  (You can add whatever path on which you want to run this command for jpg files)

the "*" will add comment to all the .jpg files present within the folder. You can add more specific name  of file if you want to add

TO EXPORT THESE COMMENTS TO A FILE :
Go to C:\MassComment within command line and run
jhead -cs C:\abc.txt C:\Mypictures\*.jpg    (you can replace abc.txt to whatever name you want to use)


Hope This Helps !!
Avatar of xenium
xenium

ASKER

Thanks a lot, I will see if i can use these. Was hoping there's something native in windows but if needed I'll consider a utility.
It can be done "natively" in windows using VBscript fairly easily, let me know if that would be viable.

An example of this can be found in this question:

https://www.experts-exchange.com/questions/28714769/Separate-Horizontal-images-and-vertical-into-separate-folders.html

~bp
And if you can use a utility, here is a solid command line one that I have used:

http://www.sno.phy.queensu.ca/~phil/exiftool/

~bp
with cripting i.e. vbscript / powershell  easily done but not without 3rd party tools otherwise as cmd.exe doesn't support it.
Avatar of xenium

ASKER

Thanks. maybe it is possible in powershell in windows 10? i can just call this from the command prompt

I.m new to this but perhaps an answer is in here
http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/26/use-a-powershell-cmdlet-to-work-with-file-attributes.aspx
yes you can use powershell to list all jpg files in a directory/ pass it to another cmdlet to look at attributes and change attributes you want.......

You can start powershell examples/explanations available at MS technet site
https://technet.microsoft.com/en-us/library/dd772285.aspx
xenium

I have had very limited exposure to Windows 10.  Perhaps this version of Windows is able to show the actual JPG Comment data better than previous versions, but my experience of Windows XP, Vista, and 7 have demonstrated that they do not display JPG Comments written by image editing software and digital cameras in Windows Explorer, and that comments written to JPG files from within Windows Explorer tend not to show in image information when the image is opened in commonly used (non-Microsoft) image viewing and editing applications.

A JPG file contains "markers" that define the start and end of the different kinds of data contained in them.  A JPG Comment is stored as a variable sized text field at 0xFF, 0xFE in the JPEG Header which uses the "COM" marker.  This marker is recognised universally by image editing applications.  From within Windows Explorer in XP, Vista, and 7, I have never seen these JPG Comments showing.

I think the confusion stems from Windows referring to textual photo descriptions as "comments" that are also stored in the files' headers, but from what I can see these are different from proper JPG Comments.

From what I can see, the Windows Explorer comments are written to a JPG file as EXIF data, whereas comments written to JPG images in image editing applications are not written as EXIF data.

As a baseline I used one image with no IPTC metadata and only the standard EXIF data and no comments created from Windows or image editing applications.  I made copies of the image and then added comments using IrfanView image editor and added comments using the file properties within Windows Explorer on a Windows XP computer.  I used comments that tell you where they were inserted from.  Here is how another image viewer and editor (XnView) shows the details of the resultant images:
User generated imageNotice how it does not show the actual comments created from Windows Explorer, but flags them as now having EXIF metadata.  This image viewer ONLY shows comments that were created from within another image editor.

Conversely, in Windows Explorer, the IrfanView comments are not shown, but the Windows ones are:
User generated image
IrfanView image editor inserts the comment as shown in the comparison between the original uncommented image and the one after I added the non-unicode comment.  I get exactly the same results with a unicode comment.
User generated image
When I inspect the image with an IrfanView AND Windows comment in a hex viewer, it is clear that Windows creates an EXIF marker and inserts its own comment there completely independently of the "JPG Comment" created by an image editing application.
User generated image
These are some of the inconsistencies you get when Microsoft implements a feature with a confusingly similar name.  The same is true of how Windows Media Player mangles ID3 Tags in MP3s, and how Apple and Adobe software add their own unique types of tags and metadata to files.

I opened the image containing the "Windows" (EXIF) comment and the IrfanView "JPG Comment" in a little standalone program named JPEGSnoop, and you can see where each of the comments are stored in the file.
User generated imageNote that this program identifies the Windows comment as [XPComment].  I don't immediately have access to a Vista, 7, 8, or 10 computer, so I have no idea how a comment created by those operating systems from the file properties would be tagged by this program.  My interpretation is that the [XPComment] is an invention of Microsoft designed to add a "Windows Comment" as a Private tag in the EXIF data area.  It could be that they didn't want such comments to interfere with existing comments created by image editing applications, but it is more likely they did this to overcome a restriction on fancy character encodings that might be imposed by the "normal" place inside JPG images for comments.  It seems that XPTitle, XPComment, XPAuthor, XPKeywords and XPSubject all seem to be used to store metadata in files, but these tags may not be recognised by all EXIF readers.

Similarly, ExifTool (version 9.95 from earlier this year) as suggested by Bill Prew, reports this for the same file (only pertinent sections included):
ExifTool Version Number         : 9.95
File Name                       : Both_Comments.jpg
File Type                       : JPEG
File Type Extension             : jpg
Comment                         : IrfanView unicode comment PLUS Windows comment
JFIF Version                    : 1.01
Exif Byte Order                 : Little-endian (Intel, II)
XP Comment                      : Windows comment PLUS IrfanView unicode comment

Open in new window


The most recent and last version of the JFIF specification (JPG format) is 1.02, whereas my test image is version 1.01, however I am sure that versions would have no consequence in this scenario.

So, what "comments" do you want to extract from and write to JPG files?  Windows comments or standard JPG Comments?

If you are doing this solely from the command line, for example using JHead, you would need to know exactly which comment you wish to read from and write to.
Avatar of xenium

ASKER

hi BillDL, thanks, to answer your question at the end "So, what "comments" do you want to extract from and write to JPG files?  Windows comments or standard JPG Comments?"

I want the comments i can see when in windows I right-click for properties and can edit the property called "Comments". I imagine this is a Windows comment but your post suggest things are maybe not so simple.

Thanks
Avatar of xenium

ASKER

I have a hunch there's a one-line answer to this that does not require a 3rd party utility: a one line that can be run in a bat file to either retrieve or edit the comment shown under windows properties for a given file. The line may be long, perhaps concatenating multiple coding lines into one instruction, and will probably pass info to/from powershell. If anyone can give this code that woudl be great thanks.

I don't mind if the instruction looks convoluted as it will be generated not typed.
That's good news that the comment field you are looking for is the one visible from within Windows Explorer and the file properties, and therefore should be easy enough to retrieve using Powershell or VBS.  Unfortunately I am expert in neither, so you will need to revert to earlier experts' suggestions.

The only method I know to get a specific file property using VBS is as follows, where you would set the name of the folder in the script and make it echo the file names in that folder followed by the respective values of the specified property number, in this case 14 is the "Comments" property (see table here: https://technet.microsoft.com/en-us/library/ee176615.aspx):

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("C:\IMAGES")

For Each strFileName in objFolder.Items
    Wscript.Echo strFileName & ": " & objFolder.GetDetailsOf (strFileName, 14) 
Next

Open in new window


I'll leave the real experts to answer this question though.
It's not too hard to access this comment for a JPG file in Powershell, but I don't know how you can update it in a similar fashion.  The objects in this approach seem to be read only.  I still think using a utility like EXIFTOOL and a BAT script would get the job done fairly simply, but since you didn't seem interested in that I haven't worked up an example.

Reference links for this example:

http://blogs.msdn.com/b/powershell/archive/2009/03/31/image-manipulation-in-powershell.aspx
https://gist.github.com/nissuk/1360596

Sample PS code:
$image = New-Object -ComObject Wia.ImageFile
$image.LoadFile("c:\temp\image.jpg")
$image.Properties("40092").Value.String()

Open in new window

~bp
Avatar of xenium

ASKER

Thanks Bill, I appreciate the info and examples which could turn out to be an option.

Is there a way to execute your powershell example in one line, in a bat file?
I'd like to be able to extract comment info from some jpg files using a dos command in a  batch file, and also be able to update comment info. Is there a way?
Can you expand on exactly what you want to do, the original post seemed a little general.  Do you want to list the comments of just one file, or all files in one folder, or a tree of files in subfolders?  What would that output look like, file names and comments?  CSV format?  etc...

And how are you wanting the update part of things to go?  Will this be for just one specific file, or all files with the same comment, or different comments for each file?  Will there be a TXT file of CSV file that will have the file names and comments to add/update?  etc...

~bp
Avatar of xenium

ASKER

hi bp, I'm looking for one line to return the comment for one file. I can then pass this plus the filename to a txt file, eg csv but this detail i can tidy up afterwards.
There maybe any number of files but at most a few dozen at a time. I'll be linking this to info kept on a google spreadsheet.
cheers
Could the Powershell code be in a separate file (.PS1) that the Bat file could call?

~bp
Avatar of xenium

ASKER

Thanks for following this up Bill. I guess so that would work. But could one line work, the following gives the idea but is wrong...

powershell -ExecutionPolicy Bypass -Command "& {$image = New-Object -ComObject Wia.ImageFile; $image.LoadFile("C:\Users\suppl\Downloads\icon_map.jpg"); $image.Properties("40092").Value.String()}"
pause

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenium

ASKER

Looking to close this soon..
Avatar of xenium

ASKER

Closing by request from ee