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.

Who is Participating?
Robberbaron (robr)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

   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

    set FSO=nothing

Sub RecurseFolder ( oFolderCurrent)
   Dim p,fn,sTmp, vItem
    sTmp=""    'build as string to reduce disk access
      for each vItem in oFolderCurrent.Items 
            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  
       'now do the folders
     for each vItem in oFolderCurrent.Items  
            if vItem.IsFolder then  
                RecurseFolder vItem.GetFolder
            end if  

end sub

Open in new window

Robberbaron (robr)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.


Robberbaron (robr)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 ?

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

Can you guide me the right script in these links....
Robberbaron (robr)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

moorthy_kulumaniAuthor 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 ?
Robberbaron (robr)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 ?


"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.
Robberbaron (robr)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.
Robberbaron (robr)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)

moorthy_kulumaniAuthor 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# ..

Appreciate your help…

Robberbaron (robr)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.
moorthy_kulumaniAuthor Commented:
Thanks for all your help...I will try posting this in C# area.
Guy Hengel [angelIII / a3]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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.