Find out "Owner" of a file as displayed by Windows Explorer

조회 수: 37 (최근 30일)
Darin McCoy
Darin McCoy 2012년 6월 8일
답변: scivision 2024년 9월 18일
I've seen some files on the FEX that allow you to get creation date / last modified date of a particular file
but does anybody know how to get the name of the "Owner" of a file? (Which is another thing displayed by Windows Explorer so it has to be accessible somehow??)
  댓글 수: 3
Darin McCoy
Darin McCoy 2012년 6월 8일
You can find details on how to show the Owner column here...
http://support.microsoft.com/kb/310297
Jan
Jan 2012년 6월 9일
Thanks, Darin! Now I understand where you find the owner.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 6월 9일
Here's one way:
fileName = 'test.m'; % Some file you're interested in.
commandString = sprintf('dir %s /Q > owner_of_%s.txt', ...
fileName, fileName);
system(commandString)
filebrowser; % Optional - Show current folder panel
% Now open the txt file you just created
% and parse it to find the owner.

추가 답변 (2개)

Jan
Jan 2012년 6월 9일
You can use .NET:
finfo = System.IO.FileInfo(FileName);
dummyAccount = System.Security.Principal.NTAccount('dummy');
Owner = char(finfo.GetAccessControl.GetOwner(GetType(dummyAccount)).Value.ToString);
There must be a more direct method to get the NTAccount type instead of creating a dummy account.
The Windows API methods are not trivial and I hesitate to implement them in a function similar to GetFileTime.
  댓글 수: 2
Darin McCoy
Darin McCoy 2012년 6월 11일
not sure how to accept both your answers? but they both worked (so i accepted Image's and voted for yours??)....thanks for the help!
Jan
Jan 2012년 6월 11일
The .NET method includes the host name also, such that file owners of network drives are identified uniquely. The DIR approach does not handle this and demands for a complicated parsing of a text file.

댓글을 달려면 로그인하십시오.


scivision
scivision 2024년 9월 18일
The owner of a file can be found using built-in Java
owner = string(java.nio.file.Files.getOwner(java.io.File(path).toPath(), java.nio.file.LinkOption.values));

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by