Notifications
Clear all

[Closed] File comparision: Rip apart getFileModDate, or is there an easier way?

I’d like to be able to check the dates between two files to see if one is newer than the other. Other than ripping apart the getFileModDate into seconds and seeing which total is higher (which is what i’m currently doing), is there an easier way? I’d hoped some fancy dotNet thing would have helped me, but so far the only file comparision examples i’ve seen are comparing the contents of the files, not the date and time.

16 Replies
1 Reply
(@rustyknight)
Joined: 1 year ago

Posts: 0

That’s a really intersting idea…I hadn’t thought of trying that until you mentioned, thanks…

Now, I haven’t tried it, but .Net has a class “System.IO.File” with a method “getCreationTime()” which returns a “DateTime” struct, which you can get a “tick” property from which “represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, Janurary 1, 0001”…

I’d imagin you could use the dotnetclass method to instance of the class

myFile = dotnetclass "System.IO.File"
myFile.open "C:\..."
myFile.getCreationDate()

I’ve not tried this at all in any fashion, but it should get you started…

Shane

 PEN

Yes the dotNet methods work great.

use dotNetClass to create an instance of it.

Thanks guys, I’ll check it out.

I think “System.IO.FileInfo” would be better : see CreationTime, LastAccessTime, LastWriteTime properties for example.

I always wondered whether we could use something like CRC for comparing files, but haven’t found any tool to do so…

Any ideas?
– MartinB

So, for example, would I call the fucntion like this?


 theFile = maxFilePath + maxFileName
 myFile = dotnetclass "System.IO.FileInfo"
 myFile.open theFile
 value = myFile.LastWriteTime
 

Or would I need to declare the value variable as a DateTime?

As it stands i’m getting some errors even at the open level.

Sorry for all the questions… I’m still trying to get my head around how dotNet declaration is handled in MXS! I hope someone else is getting something out of this discussion!

2 Replies
(@ypuech)
Joined: 1 year ago

Posts: 0

No, if the value is returned from a method you don’t need to create it.

You can get the LastWriteTime information like this:

FileName = maxFilePath + maxFileName
FileInfo = dotNetObject "System.IO.FileInfo" FileName
Hour = (FileInfo.LastWriteTime.Hour as string) + ":" + (FileInfo.LastWriteTime.Minute as string) + ":" + (FileInfo.LastWriteTime.Second as string)
Date = FileInfo.LastWriteTime.DayOfWeek.ToString() + " " + (FileInfo.LastWriteTime.Month as string) + "\\" + (FileInfo.LastWriteTime.Day as string) + "\\" + (FileInfo.LastWriteTime.Year as string)
Print "Last Write Time on " + Date + " at " + Hour
(@rustyknight)
Joined: 1 year ago

Posts: 0

Way cool, I was trying to work out how to pass parameters to constructors! Cheers!

Brilliant, thanks Yannick! Out of interest, I couldn’t find the hour/minute/second part in the MSDN reference in relation to lastWriteTime. Where do these properties come from? Is it just something inherent from the DateTime object, or is it something from the FileInfo properties?

2 Replies
(@rustyknight)
Joined: 1 year ago

Posts: 0

There apart of the DateTime class, check out http://msdn2.microsoft.com/en-us/library/system.datetime.aspx for more details

(@erilaz)
Joined: 1 year ago

Posts: 0

Ah, yes just found it, silly me!

So like you were saying earlier, all I would have to do is compare fileA’s and fileB’s
FileInfo.LastWriteTime.Ticks to get what i’m after?

That’s how I’d see it. Seen as ticks is a long value, you should be able to compare the value to determine which file is “younger”

if file1.GetLastWriteTime().ticks < file2.GetLastWriteTime().ticks then
    --File 1 is younger

ps – Haven’t tested this…

Shane

Brilliant, that just saved me about 10 lines of code!
Really, really appreciate it guys. This is why I love this forum.

One day i’ll finally get my head around the dotNet interfacing. This has been a fantastic learning experience so far.

ps – Haven’t tested this…

Don’t worry, it seems to work fine.

I gotta tell ya, I’m not a big microsoft fan, but the dotnet api kicks the old activex api’s butt. The whole API tends to revolve around a common design paradigm, which can make it eaiser to learn over time – the more you play with it, the eaiser to gets.

Page 1 / 2