This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 17 - Pages: 2 [ 1 2 | Next ] - Last Post: 28 Sep 22, 13:54 Last Post By: wiener30
wiener30

Posts: 17
Registered: 8-Sep-2009
How to compare two files
Posted: 10 Nov 20, 17:14
 
  Click to reply to this thread Reply
I want to copy additional files from images to output directory.

How to compare if the files are different in order not to copy the same file.

Could somebody show what methods should I use to compare file size and modification date?
AndreWolff

Posts: 1,159
Registered: 14-Dec-2007
Re: How to compare two files
Posted: 10 Nov 20, 17:54   in response to: wiener30 in response to: wiener30
 
  Click to reply to this thread Reply
RobM

Posts: 3,818
Registered: 4-Aug-2006
Re: How to compare two files
Posted: 10 Nov 20, 18:04   in response to: wiener30 in response to: wiener30
 
  Click to reply to this thread Reply
wiener30 wrote:
I want to copy additional files from images to output directory.

How to compare if the files are different in order not to copy the same file.

Could somebody show what methods should I use to compare file size and modification date?

What file types and how are you copying them currently?
wiener30

Posts: 17
Registered: 8-Sep-2009
Re: How to compare two files
Posted: 10 Nov 20, 18:25   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Mainly kml and gpx files.

I would like to do in Java within jAlbum.

There is an example on web

http://www.avajava.com/tutorials/lessons/whats-a-quick-way-to-tell-if-the-contents-of-two-files-are-identical-or-not.html

but it requires an additional library. I thought my be there is something similar in jAlbum.
RobM

Posts: 3,818
Registered: 4-Aug-2006
Re: How to compare two files
Posted: 10 Nov 20, 19:38   in response to: wiener30 in response to: wiener30
 
  Click to reply to this thread Reply
wiener30 wrote:
Mainly kml and gpx files.

I would like to do in Java within jAlbum.

There is an example on web

http://www.avajava.com/tutorials/lessons/whats-a-quick-way-to-tell-if-the-contents-of-two-files-are-identical-or-not.html

but it requires an additional library. I thought my be there is something similar in jAlbum.

It can be done within jAlbum, either as an external tool or by the skin being used - for example in predir.bsh, postdir.bsh etc.

If the skin you are using supports such map files, maybe posting a request to the skin developer would be best for you.
MarkusD

Posts: 627
Registered: 13-Apr-2006
Re: How to compare two files
Posted: 10 Nov 20, 19:47   in response to: wiener30 in response to: wiener30
 
  Click to reply to this thread Reply
wiener30 wrote:
Mainly kml and gpx files.
If you really just want to compare kind of text files, and kml and gpx are just ordinary text files, then Notepad++ is just the right tool for you. You just need to download the "Compare" plugin https://github.com/jsleroy/compare-plugin
AndreWolff

Posts: 1,159
Registered: 14-Dec-2007
Re: How to compare two files
Posted: 10 Nov 20, 22:25   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
The compare plugin is in the standard notepad ++ installation.
JeffTucker

Posts: 8,212
Registered: 31-Jan-2006
Re: How to compare two files
Posted: 10 Nov 20, 22:34   in response to: MarkusD in response to: MarkusD
 
  Click to reply to this thread Reply
Please explain how any of this helps the original poster, who said:

I would like to do in Java within jAlbum.

How would he invoke Notepad++ from, say, a finally.bsh file?
davidekholm

Posts: 3,473
Registered: 18-Oct-2002
Re: How to compare two files
Posted: 11 Nov 20, 12:03   in response to: JeffTucker in response to: JeffTucker
Helpful
  Click to reply to this thread Reply
You can solve this by adding a "postdir" file to the folder of the skin you use. A "postdir" file is executed after the processing of each directory during a make album process. If it's a JavaScript based skin like Tiger or Lucid for instance, then put this code inside "postdir.js":
var IO = Java.type("se.datadosen.util.IO")
for each (var f in imageDirectory.listFiles()) {
	if (f.getName().endsWith(".kml") || f.getName().endsWith(".gpx")) {
		IO.copyFile(f, outputDirectory, false);
	}
}
The IO.copyFile(src, dest, false); call will ensure that the file is only copied if it hasn't already been copied. It looks at file dates to determine whether the source file needs to be copied again.

If the skin you use is BeanShell based (scripted Java), then you can use this code instead:
for (f : imageDirectory.listFiles()) {
	if (f.getName().endsWith(".kml") || f.getName().endsWith(".gpx")) {
		IO.copyFile(f, outputDirectory, false);
	}
}
You can determine whether the skin is JavaScript based or BeanShell based by the extension of the "init" file of the skin. If it's "init.js", then it's JavaScript based, if it's "init.bsh" then it's BeanShell based.
davidekholm

Posts: 3,473
Registered: 18-Oct-2002
Re: How to compare two files
Posted: 11 Nov 20, 12:06   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
You can also make these file types known to jAlbum so jAlbum does the copying using the ordinary code. Simply add support for the file types you like by editing system/filetypes.xml.
RobM

Posts: 3,818
Registered: 4-Aug-2006
Re: How to compare two files
Posted: 11 Nov 20, 12:17   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
You can also make these file types known to jAlbum so jAlbum does the copying using the ordinary code. Simply add support for the file types you like by editing system/filetypes.xml.
It would be nice for users if they could append file types, by adding a filetypes.xml to the configuration directory. That way, jAlbum updates won’t need to have that file re-edited.
davidekholm

Posts: 3,473
Registered: 18-Oct-2002
Re: How to compare two files
Posted: 11 Nov 20, 12:20   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
davidekholm wrote:
You can also make these file types known to jAlbum so jAlbum does the copying using the ordinary code. Simply add support for the file types you like by editing system/filetypes.xml.
It would be nice for users if they could append file types, by adding a filetypes.xml to the configuration directory. That way, jAlbum updates won’t need to have that file re-edited.

Good idea
wiener30

Posts: 17
Registered: 8-Sep-2009
Re: How to compare two files
Posted: 11 Nov 20, 13:34   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thank you very much, helps a lot.
davidekholm

Posts: 3,473
Registered: 18-Oct-2002
Re: How to compare two files
Posted: 11 Nov 20, 13:35   in response to: wiener30 in response to: wiener30
 
  Click to reply to this thread Reply
You're welcome
AndreWolff

Posts: 1,159
Registered: 14-Dec-2007
Re: How to compare two files
Posted: 11 Nov 20, 15:48   in response to: wiener30 in response to: wiener30
 
  Click to reply to this thread Reply
wiener30 wrote:
I want to copy additional files from images to output directory.
I am curious, why do you like to do that and what skin are you using?
Are you publishing photos of gps tours?
Could you give an example of such an album?
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums