Go Premium for a chance to win a PS4. Enter to Win

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 769

# Enmurate file properties resides on File share

We have a requirement to pull few file properties for around 10 TB of files stored in the file server.

We are trying to pull properties like filename, owner of the file, the location (directory), size, Last accessed, Last modified, created date etc.,  output to a excel file.

We cannot use any free tools in our environment and we would like to do it by some scripts.

What we have already tried is using powershell but unfortunately we could not get the file properties which are more than 260 characters. Here is the powershell command we have used.
Get-ChildItem -path \\servername\share  -recurse | Select-Object Name, CreationTime, LastAccessTime, LastWriteTime, Fullname,@{n='Owner';e={ (Get-Acl \$_.Fullname).Owner }} | Export-Csv c:\out.csv

I am looking to pull all the file properties including the files which are more than 260 characters. Please help me with the script and some lead on this.

-Ram
0
moorthy_kulumani
• 9
• 4
5 Solutions

Commented:

shows how to lots of these using VBScript and the FSO.

recursion is not hard either.  check wether the FSO can return all the data you want.

http://classicasp.aspfaq.com/files/directories-fso/how-do-i-find-the-owner-author-and-other-properties-of-a-file.html

0

Commented:
for the owner info, you have to use WMI or GetDetailsOf.  the later is different for W2000 than XP+.   can we assume that no Win2000 involved ?

0

Author Commented:
Those file shares are hosted in Windows 2003 server.

Can you guide me the right script in these links....
0

Commented:
just realised that Powershell cn create the Shell object and may be best in your envionment.  see text at bottom of http://msdn.microsoft.com/en-us/library/bb787872%28v=VS.85%29.aspx

0

Commented:
my test vbs file.

works ok on local PC and across a mapped network drive.

'EE Robberbaron
'Q = http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26492218.html#a33741948
'v1  23.Sept.2010

Const ForReading  =  1
Const ForWriting = 2
Const ForAppending = 8
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim strDirectory, strFile, strText, fTmp

dim sLogFolder , oFSO, oFolder, vItem , cFilesLIst, iLoc
dim sLogFiles , sTagCode1, sTagCode2, sExtraLine , sCSVname , oCSVFile , sResultLine

sOrigFolder="C:\ee"
sOutputCSV = "C:\filedatalist.csv"

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oOutputFile = oFSO.OpenTextFile(sOutputCSV, ForWriting, true)

Set oSH = CreateObject("Shell.Application")
set oFL = oSH.Namespace(sOrigFolder)

if (not oFL is nothing) then

RecurseFolder oFL
end if
oOutputFile.Close

set FSO=nothing
wscript.quit

Sub RecurseFolder ( oFolderCurrent)
Dim p,fn,sTmp, vItem
sTmp=""    'build as string to reduce disk access

for each vItem in oFolderCurrent.Items
stmp=""
if not vItem.IsFolder then
p = vItem.path
fn = right(p, len(p)-instrRev(p,"\"))
sTmp = sTmp & fn  & ","  'filename
sTmp = sTmp & p  & ","  'full path & filename
sTmp = sTmp & vItem.type  & ","  'windows interanl type
sTmp = sTmp & chr(34) & oFolderCurrent.GetDetailsOf(vItem,1) & chr(34) & ","    'size in kB
sTmp = sTmp & oFolderCurrent.GetDetailsOf(vItem,4)  & ","    'created
sTmp = sTmp & vItem.modifyDate  & ","                        'modified
sTmp = sTmp & oFolderCurrent.GetDetailsOf(vItem,5)  & ","    'date accessed
sTmp = sTmp & oFolderCurrent.GetDetailsOf(vItem,8)  & ","    'owner
sTmp = sTmp & oFolderCurrent.GetDetailsOf(vItem,9)  & ","    'creator
oOutputfile.writeline sTmp
end if
next

'now do the folders
for each vItem in oFolderCurrent.Items
if vItem.IsFolder then
RecurseFolder vItem.GetFolder
end if
next

end sub

0

Author Commented:
Tahnks, Let me test and confirm... I assume it can take files with more than 260 letters length, Should i use unc name \\server\share or mapped drive letter ?
0

Commented:
1/ I cant test the filename length as XP has a 256 character path limit.
How have you formed paths of more than 256 characters on windows. Other than unicode ?

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

"To specify an extended-length path, use the "\\?\"         prefix. For example, "\\?\D:\<very long path>". (The characters < > are used here         for visual clarity and cannot be part of a valid path string.)
Note  The maximum path of 32,767 characters is approximate, because the "\\?\" prefix may be         expanded to a longer string by the system at run time, and this expansion applies to the total length.
The "\\?\" prefix can also be used with paths constructed according to the universal naming         convention (UNC). To specify such a path using UNC, use the "\\?\UNC\" prefix. For example,         "\\?\UNC\server\share", where "server" is the name of the computer and         "share" is the name of the shared folder. These prefixes are not used as part of the path         itself. They indicate that the path should be passed to the system with minimal modification, which means that         you cannot use forward slashes to represent path separators, or a period to represent the current directory, or         double dots to represent the parent directory. Because you cannot use the "\\?\" prefix with a         relative path, relative paths are always limited to a total of MAX_PATH         characters."

2/ Going from the above MSDN article, you need to use the special pathing to access filenames longer than 256.    It would be more efficient to run the script on the server of course , using the \\?\d: path.

3/ Note that I cant get the \\?\UNC\server\share or \\?\D: method to work in my testing, where std unc naming \\server\share works fine.
0

Commented:
looks like you need to use c++ , c#

There are no such constants defined in the FCL, the IO namespace classes are
wrappers arround the Win32 ANSI IO API's, so the same values apply. Anyway
when you exceed the max. path size you will get an exception thrown on you.
Note also that you can open files using the UNICODE version of the
CreateFile API through PInvoke, and use the file handle returned in a
FileStream instance, that way you can access files with a path name max. up
to 32768 bytes.
0

Commented:
the std c# FileInfo class still has the 255 character limit so this is a real issue for you.  your app needs to be c++ or c# with Pinvoke (which i think achieve the same thing)
http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath%28v=vs.71%29.aspx

0

Author Commented:
The VB Script is working ...I don’t know wherther or not I have 260 + characters files....I am not sure how we havecreated  more than 260 characters files in our servers…
The VB script you have given can pull the files more than 260 characters? If not could you please share the C# script, I really don’t get a clue on how can write one with C# ..

0

Commented:
1/ I dont believe the VBScript can pull more than 260 characters due to limitation of the Windows API.  Note it is the TOTAL PATH limit that is 260char.

2/ I dont have any C# code that uses the PInvoke as I'm a C# beginner.  You will have to ask in the C# topic. I think you can add that topic to this one. Or ask a new Q.

3/ there was a script that checked for long pathnames by trapping the particular error. At least that way you can tell the extent of your issue.

Sorry, no more I can help with.
0

Author Commented:
Thanks for all your help...I will try posting this in C# area.
0

Billing EngineerCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

## Featured Post

• 9
• 4
Tackle projects and never again get stuck behind a technical roadblock.