Solved

Enmurate file properties resides on File share

Posted on 2010-09-22
15
728 Views
Last Modified: 2012-05-10
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
Comment
Question by:moorthy_kulumani
  • 9
  • 4
15 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 33741762
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/

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
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 33741909
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
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 33741939
Those file shares are hosted in Windows 2003 server.

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

Expert Comment

by:Robberbaron (robr)
ID: 33741948
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
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 33742241
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

Open in new window

0
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 33742340
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
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 500 total points
ID: 33749634
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 33749703
0
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 500 total points
ID: 33749738
looks like you need to use c++ , c#
http://bytes.com/topic/c-sharp/answers/548142-maximal-path-maximal-file-name-length

 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
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 500 total points
ID: 33749782
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
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 33751542
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…

0
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 500 total points
ID: 33753547
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
 
LVL 3

Author Comment

by:moorthy_kulumani
ID: 33763582
Thanks for all your help...I will try posting this in C# area.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34986425
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

706 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

20 Experts available now in Live!

Get 1:1 Help Now