Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Checking if files are identical?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st Jul 2010 14:18
How would I do this?

TheComet

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 21st Jul 2010 14:25
In dbpro load the 2 files into memblocks and just do a byte by byte compare. If you just want to do it in windows then CSdiff is a neat little program which will highlight the differences between files.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Jul 2010 15:28
Slightly faster:

First, check that the files are the same size - if they aren't then you already know they are different.

Then you can map each file into a bank, and then compare their content using dwords or double integers. If the files aren't exact multiples of 4 (dword) or 8 (double integer) in size, then finish comparing the rest using byte comparisons.

mr_d
DBPro Tool Maker
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 21st Jul 2010 16:14
Another way in Windows, is to go to the command prompt, and use the following command:

fc.exe /b file1 file2

the /b tells it to do a binary (byte by byte) comparison.
if you don't include this argument, then the comparison will be done as text.

(\___/)
(='.'=) Copy bunny into your signature to
("_(" help him gain world domination.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2010 17:20
What about all the other information stored in File Properties such as Date Created, etc? How would we check all those?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Jul 2010 23:29
File properties are not stored inside the file. You would have to call the windows API to get them

http://msdn.microsoft.com/en-us/library/aa364946.aspx

[b]
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2010 23:38
Quote: "File properties are not stored inside the file."


I know. That's why I asked.

Quote: "You would have to call the windows API to get them"


I had a horrible feeling someone would say something like that.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Jul 2010 23:39
would it be easier to make a hash of file and just compare that?


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Jul 2010 23:48
Depends how unique the hash is I suppose - but since you'd need to scan both files to compute the hash value would you have gained anything?
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 22nd Jul 2010 00:50 Edited at: 22nd Jul 2010 00:59
Quote: ""You would have to call the windows API to get them""


If I remember rightly someone asked how to get file attributes a few months ago and ended up having to resort to API calls, because otherwise you have to use the file checklist functions and trawl through the whole list.

edit: This is the thread I was thinking of, but it's only for file date.

http://forum.thegamecreators.com/?m=forum_view&t=170123&b=1
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jul 2010 00:51
Which is easier?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jul 2010 01:03
Quote: "Which is easier? "


Probably the checklist functions, but I usually go for quality and performance, which would be the API?

TheComet

sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 22nd Jul 2010 01:15
Reading the help it looks like you can't get all the attributes from find first/next so it's API all the way. (As Diggsey already mentioned)
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Jul 2010 01:45 Edited at: 22nd Jul 2010 01:47
It's really not that hard to do the API call, even without any external plugins.

- Load 'Kernel32.dll'
- Make a 36 byte memblock
- Call 'GetFileAttributesExA' in the previously loaded dll
- First parameter is the file or directory name
- Second parameter is 0
- Third parameter is a pointer to the memblock ('get memblock ptr')
- Result is non-zero if the function succeeds

The data will be stored in the memblock in this format:



The file attributes are a bitwise combination of the flags specified here: http://msdn.microsoft.com/en-us/library/ee332330.aspx

All times are the number of 100 nanosecond intervals since January 1, 1601 (UTC)

For directories, 'File Size' is meaningless, and all three times are the creation time of the directory.

[b]
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jul 2010 02:03 Edited at: 22nd Jul 2010 02:04
That isn't the whole story surely?

For example, the File Properties of the file DBPCompiler.exe on my system show, among other things, the following:



How does all that fit into those few bytes?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Jul 2010 12:59 Edited at: 22nd Jul 2010 13:01
That information is a bit more complicated to get. The attributes aren't the same for all file types, and so you can't just use simple WINAPI functions.

This may help though:
http://www.codeproject.com/KB/shell/CFileProperty.aspx

Also, I think some of that information might be stored inside the file.

If you need it that badly you could always ask IanM to add it to his plugins

[b]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Jul 2010 15:28
As this thread has continued despite my previous post of earth-shattering importance, I guess just checking the content isn't enough?

The properties information is contained within the binary for the most part, so will be captured by comparing the file data ... unless that information is required for some other purpose.

Other information, such as timestamps could be gathered fairly simply, although their form would need to be decided (One of the many 'standard' dos/windows timestamps? Unix timestamp? String, but in what form again?)

Some information that no one has talked about though is ownership and permissions ... are they important for this?

The problem here is that TheComet hasn't told us what he means by 'identical' files.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Jul 2010 15:34
Quote: "The problem here is that TheComet hasn't told us what he means by 'identical' files."


I guess I mean files that have different content when you compare them, including file size, date modified, and other things like that And it seams the most efficient way of checking this is checking the properties of the files.

I was aiming for an update system for my game.

Thanks everyone

TheComet

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Jul 2010 15:36
@IanM
Some information isn't stored in the file. You can set the author and other properties on a plain text file, and the contents remain unchanged.

[b]
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Jul 2010 15:37
Quote: "The problem here is that TheComet hasn't told us what he means by 'identical' files."


True, but we've moved on to another issue regardless of the original intent - i.e. we're following a well-established Forum practice.

Login to post a reply

Server time is: 2026-07-25 05:32:40
Your offset time is: 2026-07-25 05:32:40