CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Parsing data from TXT file into XMP format with ExifTool

 

First page Previous page 1 2 Next page Last page  View All


teddoff
Novice

May 19, 2015, 5:53 AM

Post #26 of 38 (6850 views)
Re: [Zhris] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

I know it's tedious, sorry, but let me get back to you when I have it working.

Thanks


Laurent_R
Veteran / Moderator

Jun 22, 2016, 10:25 AM

Post #27 of 38 (6168 views)
Re: [teddoff] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

Test post


garry664
Novice

Jun 22, 2016, 5:56 PM

Post #28 of 38 (6157 views)
Re: [Laurent_R] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

I finally got Perl installed and working with ExifTool, sorry for the delay, I had a lot of things on my plate!

Using the code from Chris I found an error on line 10 every time I ran the script:


Code
    open my $filehandle_txt, '<', $filepath_txt or die "cannot open '$filepath_txt': $!";



Even with the script in the same folder as the txt files I get this. However, as the format of the image and accompanying text files means that the file image format is in the same name as the text file, I found the script got confused, so only when I removed that first instance did it even read the file:

Image file: "123.gif"
Sidecar text file: "123.gif.txt"

*this is so that the files stay next to the image file they belong to*


So it won't process the files in the folder, what exactly is going wrong please?


(This post was edited by garry664 on Jun 22, 2016, 6:09 PM)


Laurent_R
Veteran / Moderator

Jun 22, 2016, 11:20 PM

Post #29 of 38 (6148 views)
Re: [garry664] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

Please provide the exact code that you are running and the exact error message that you get, as well as warnings if any.


garry664
Novice

Jun 23, 2016, 12:33 AM

Post #30 of 38 (6147 views)
Re: [Laurent_R] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

This code was originally provided by Zhris:


Code
use strict; 
use warnings;
require Image::ExifTool;

for my $filepath_gif ( <*.gif> )
{
my $filepath_txt = $filepath_gif . '.txt';
my $filepath_xmp = $filepath_gif . '.xmp';

open my $filehandle_txt, '<', $filepath_txt or die "cannot open '$filepath_txt': $!";
my %hash = map { my$s=$_;$s=~s/[\s:]*$//;$s } grep /\S+/, <$filehandle_txt>;
close $filehandle_txt;

my $exifTool = new Image::ExifTool;
$exifTool->SetNewValue(Author => $hash{Title}) or die;
$exifTool->WriteInfo( undef, $filepath_xmp, 'XMP' );
}



In Terminal (OSX) I execute the command:


Code
perl test1.pl


The message I receive is:

"cannot open '123.gif.txt': No such file or directory at test1.pl line 10."

But, of course, the file does exist, so I'm not sure what the issue is?

Thanks!


FishMonger
Veteran / Moderator

Jun 23, 2016, 8:20 AM

Post #31 of 38 (6140 views)
Re: [garry664] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

Maybe it's a case problem where the actual file ext is really '.TXT' instead of '.txt'.

What is the output of this command?

Code
ls -l 123.gif*



Laurent_R
Veteran / Moderator

Jun 23, 2016, 9:33 AM

Post #32 of 38 (6137 views)
Re: [garry664] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

Perhaps you should try to replace:

Code
for my $filepath_gif ( <*.gif> )

with:

Code
for my $filepath_gif ( <*.gif.txt> )

and make the relevant changes in the loop. At least you would be sure to try to open files that really exist in the directory.

Or else add a code line to check for the existence of the file before trying to open it:


Code
my $filepath_txt = $filepath_gif . '.txt';  
say "File $filepath_txt does not exist" and next unless -f $filepath_txt ;
# ...


This is probably not going to solve the problem, but at least the diagnosis might become clearer.


garry664
Novice

Jun 27, 2016, 5:20 PM

Post #33 of 38 (6052 views)
Re: [Laurent_R] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

I tried changing it to "<*.gif.txt>" before, I thought that it could be the reason, but it wasn't as it just adds another ".txt" on to the end:


Code
cannot open '123.gif.txt.txt': No such file or directory at test2.pl line 10.


The other code spat out the following:


Code
"my" variable $filepath_txt masks earlier declaration in same scope at test3.pl line 18. 
String found where operator expected at test3.pl line 19, near "say "File $filepath_txt does not exist""
(Do you need to predeclare say?)
syntax error at test3.pl line 19, near "say "File $filepath_txt does not exist""
Execution of test3.pl aborted due to compilation errors.


I added the code wishing the curly braces, at the end of the function, not sure if that was what you wanted?

Unfortunately, it didn't work.


garry664
Novice

Jun 27, 2016, 5:23 PM

Post #34 of 38 (6049 views)
Re: [FishMonger] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post


In Reply To
Maybe it's a case problem where the actual file ext is really '.TXT' instead of '.txt'.

What is the output of this command?

Code
ls -l 123.gif*




All extensions are in lower case, I think that I just wanted to emphasise that in the OP title.

Output:

Code
-rwxrwxrwx@ 1 Andi  staff  873930  4 Mar  2015 1425.gif  
-rwxrwxrwx@ 1 Andi staff 614 4 Mar 2015 1425.gif.txt



FishMonger
Veteran / Moderator

Jun 28, 2016, 9:36 AM

Post #35 of 38 (6024 views)
Re: [garry664] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

Lets take a step back and remove all of the Image::ExifTool stuff and make a test script that just outputs a list of files to see what perl "sees".

The script needs to be in the same directory as the gif/txt files AND you need to cd into that directory to run the script.

Code
#!/usr/bin/perl 

use strict;
use warnings;
use diagnostics;

foreach my $file (<*.gif*>) {
print "$file\n";
}


After verifying that the script outputs the matching gif/txt files, then run this test script.

Code
#!/usr/bin/perl 

use strict;
use warnings;
use diagnostics;

foreach my $file (<*.gif>) {
chomp $file; # this isn't really needed but,
# I put it in on the odd chance that
# the diamand operator in the old perl
# appended a line terminator to the filename

print "$file\n";

my $txt_file = "$file.txt";
if (-e $txt_file) {
print "$txt_file exists ";

if (-r $txt_file) {
print "and is readable\n";
}
else {
print "BUT is NOT readable\n";
}
}
else {
print "$txt_file does not exist\n";
}

}


If the print statement from either of the else blocks gets outputted, then you need to take a closer look at either the spelling of the filename or the permissions on the file.


(This post was edited by FishMonger on Jun 28, 2016, 9:46 AM)


garry664
Novice

Jun 28, 2016, 12:19 PM

Post #36 of 38 (6015 views)
Re: [FishMonger] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

Many thanks, I tried the sample code and everything seems to be in working order: all files are recognised and the txt files "exist" and are "readable".


teddoff
Novice

Jun 30, 2016, 12:53 PM

Post #37 of 38 (5946 views)
Re: [FishMonger] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post

I'm not sure then why the original code doesn't export the txt files as xmp ones?


Zhris
Enthusiast

Jul 2, 2016, 7:39 PM

Post #38 of 38 (5899 views)
Re: [teddoff] Parsing data from TXT file into XMP format with ExifTool [In reply to] Can't Post


Quote
"cannot open '123.gif.txt': No such file or directory at test1.pl line 10."


'123.gif' doesn't have a corresponding '123.gif.txt'.

I recommend you use Fishmonger's verbose code as a base and take the relevant parts from mine. Check through the output very carefully.

Chris

First page Previous page 1 2 Next page Last page  View All
 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives