Solved

File and Folder IDs

Posted on 2002-04-02
24
140 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
ID: 6913513
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
ID: 6913514
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
ID: 6913523
Double post... why? I sent it once.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6913538
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
ID: 6913609
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
ID: 6913706
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
ID: 6913709
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
ID: 6913769
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
ID: 6913791
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
ID: 6913804
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6913814
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
ID: 6913894
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:EasyAim
ID: 6913903
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
ID: 6913931
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
ID: 6913963
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
ID: 6913980
Nope, the solution has to be applicable to any type of file.

Zaphod.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6913987
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
ID: 6914002
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
ID: 6914108
Reading the FAT....? (if such thing could be done with VB)
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6914183
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
ID: 6914422
But you could use one of them if you know in which environment you are "running"....
0
 

Expert Comment

by:EasyAim
ID: 6916122
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
ID: 6925495
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
ID: 6929048
Thanks.  Sorry we couldn't totally solve it, but I suspect that at least some of the ideas were helpful.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

12 Experts available now in Live!

Get 1:1 Help Now