Solved

File and Folder IDs

Posted on 2002-04-02
24
139 Views
Last Modified: 2010-05-03
Hi,

I was wondering if there is a way to obtain a unique ID for each file and folder which stays the same regardless of whether the contents are changed, or whether it is renamed or moved. I looked into the GetFileInformationByHandle API but apparently its ID field can change when the file is modified. Anyone have any ideas?

Thanks,

Zaphod.
0
Comment
Question by:Z_Beeblebrox
  • 8
  • 7
  • 6
  • +1
24 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
interesting... i think it could be possible but don'tknow how. Renaming...mmmmmm, i doubt... but is just a guess.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
interesting... i think it could be possible but don'tknow how. Renaming...mmmmmm, i doubt... but is just a guess.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Double post... why? I sent it once.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
If you're talking about a file that you create, then you can add application properties to make it unique.  For example, add something into the comments section of the project properties' Make tab.

Other than that, you may be able to check the properties of any executable to search for something unique, like version number.

But if your intent is to permanently stamp a file with an ID, I don't think that's possible.  Biologically speaking, the only reason that living things can be uniquely identified is because every cell in our bodies has the almost the same unique DNA, and with enough billions of combinations, you can pretty easily tell that a given cell belongs to a certain person.

In computer datastreams, you don't get that level of redundancy.  Instead, you get an identifier name, then a flood of data.  To uniquely identify something, the best you can get is either an exact match or a profile that seems to match.

This is really the same problem that virus detection software has.  The software looks for a code match to identify the virus (but if it happens to find it inside another virus detection program, it thinks it's a virus!)  Now, if someone changes a few bytes, the virus may work the same, but its profile has changed.  It may even be harmless!  Should these two be considered the same file just because a few bytes changed?  Very hard to say, but probably not.

As such, the only way to really identify a file is through outside resources, like a registry reference or "metadata" attached to the file (like the app info.)
0
 

Expert Comment

by:EasyAim
Comment Utility
Richie,
  The double post happens whenever the browser is refreshed while still residing on your last comment. (I learned the hard way.)

This is a good question and I often have a need for the same thing.

Someone help me out, but it looks like the only attributes that you can change on a file are:

  filename, size, realsize, createDate, modifyDate, AccessDate, ReadOnly, Hidden, Archive.

  I guess what we're looking for is a GUID unchangeable property that is unique all over the world every time a file is created.

  I have to agree with rspahitz in that the only thing possible may be to insert a unique id into the file contents... which is not always possible.

0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Hi,

I don't want to add a file ID, I just want to obtain one. I am trying to keep track of all files in a given directory, so that I can tell if a file has had its contents changed, been renamed, moved, whatever. The closest thing that I have found to this, other than the previously mentioned GetFileInformationByHandle ID is the create date, but I don't think that is unique enough.

Zaphod.
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
BTW, before anyone brings it up, neither of the windows provided FileChange notification systems (the documented and the undocumented one) provide me with enough resolution to figure this out, although the undocumented one does come close, but I am not confortable using it.

Zaphod.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 100 total points
Comment Utility
If you already have a profile of the files in question, then you can check to see if anything changed, although it will not be easy without help from Windows.

For example, we have a system in place that checks a folder to see if one of our developers in another department changed any of the files.  When we run the application, it compares the files against the previous run and determines:

* Were any files added? (by filename, possibly meaning a name change)
* Were any files removed?
* Did any of the dates of the files change?
* Did any of the sizes of the files change?
* Did any of the file's bytes change?

The last question is the hardest to answer, but we do a byte-by-byte comparison.  If this is impractical, you may be able to do a checksum comparison where the bytes are counted in such a way that they give a number.  If the numbers don't match, the file changed.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
But you could monitoring changes in a directory if that is what you want:
(i don't know if is close enought)
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=24032&lngWId=1
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Hi,

The problem that I am not sure how to solve is how do I figure out reliably which file was renamed, and what was it renamed to, or which file was moved, and where was it moved to, I need to differentiate between a move and a delete/create combination. Copying would be nice but I don't think it is practical.

Zaphod.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Is this an environment that you can control?  For example, if it's NT/2000-based, I think you can control what functions people have.  With those controls, you can possibly prevent them from deleting files.

Furthermore, maybe you could offer the users a new file manager tool so that all moves are monitored by your own app.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Expert Comment

by:EasyAim
Comment Utility
hmmmmm, it sounds like to me if you really, really wanted to do it right, you're going to have to take over the entire operating system and hijack any of the usual rename and copy functions.

In the old days this was easy to do but this new-fangled Windows crap makes it a little trickier.

If the users are insulated from the operating system anyway (like "Call Center" personnel and similar who are not developers or professionals) you could make a standalone routine to allow them the functionality of renaming and copying but you of course are tracking everything.


0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Hi,

The problem is not users, it is files handled by other applications. There is no way that I can control what they do with files without creating my own file system, just a tad above my level of expertise :)

The easiest way to do this would be to have windows provide me with a file ID that stays the same regardless of what changes are made to the file, short of copying or deleting it. If there is no such ID, then I will have to do things the very hard way, and I cannot get completely accurate information.

Zaphod.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Are there specific types of files that you're concerned about.  If so, you may be able to get around the problem by encoding the files with your own unique ID.

For example, if you're only concerned about .exe files, you can append a unique ID to the end of the files without any impact.  Other files may have similar opportunities, although I haven't explored any others.
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Nope, the solution has to be applicable to any type of file.

Zaphod.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Well, then the only way I can see if to mirror the entire thing and compare...an ominous task, especially if you need it real-time.   Hmm...how about if you lock folders so that they're read-only?  I know Unix lets you set folder permissions like that but I don't think Windows does unless 2000 or XP changed that.
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Heh, no I don't want to prevent the software from doing anything, I just want to monitor it. I was already planning on creating a store of all of the files in the directory, but since multiple changes can happen faster than my app can respond, I cannot detect all changes reliably without some sort of identifier. Since there doesn't seem to be one, I will leave this question open until tonight, when I can check some things out. If not one has a solution by then I will split some points between you three.

Zaphod.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Reading the FAT....? (if such thing could be done with VB)
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Thats what I was thinking, the only problem is that there are then at least 4 potential file systems, FAT16, FAT32, NTFS4 and NTFS5, seems impractical.

Zaphod.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
But you could use one of them if you know in which environment you are "running"....
0
 

Expert Comment

by:EasyAim
Comment Utility
I'll check into it but now that you mention the FAT, I vaguely remember reading that NT systems track file re-naming somewhere....   I'll let you know if I come across it...
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
Comment Utility
Thanks all for your help, unfortunately there is no solution. In the end, I am using ReadDirectoryChangesW and wrapping it to figure out exactly what is going on. I posted points for EasyAim and Richie. Sorry I was so long getting back to this question, it just kept slipping my mind.

Zaphod.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Thanks.  Sorry we couldn't totally solve it, but I suspect that at least some of the ideas were helpful.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now