views:

37

answers:

3

Hi All,

I need a script that could ran and pull information from any drive on a windows operating system (Server 2003), listing all files and folders which contain the following fields:

  • Full file path (e.g. C:\Documents and Settings\user\My Documents\testPage.doc)
  • File type (e.g. word document, spreadsheet, database etc)
  • Size
  • When Created
  • When last modified
  • When last accessed

Any help is appreciated.

Thanks

+1  A: 

try this vbscript

Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
  If objDIR <> "\System Volume Information" Then
    For Each eFolder in objDIR.SubFolders
        Go eFolder
    Next   
  End If
    For Each strFile In objDIR.Files
        WScript.Echo "Full Path: " & strFile.Path
        WScript.Echo "File Size(bytes): " & strFile.Size
        WScript.Echo "File Date modified: " & strFile.DateLastModified
        WScript.Echo "File Date Created: " &  strFile.DateCreated
        WScript.Echo "File Date accessed: " & strFile.DateLastAccessed

    Next 
End Sub 

on command line

c:\test> cscript //nologo myscript.vbs c:\
ghostdog74
Thanks, am quite a novice on this, where in the code do i specify the location of the drive/path and also do i save the file as a vbs and run it through CMD?
Khalid
you can run it on the command line as i indicated. Or you can also put that statement in a batch file.
ghostdog74
Hi sorry i get this error when trying to run it:"Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. C:\temp\test.vbs(3, 1) Microsoft VBScript runtime error: Subscript out of range"
Khalid
Also would it be possible to export this to a spreadsheet document either excel or csv file
Khalid
subscript out of range means you didn't input a drive letter. see my example command line again. there is a "c:\" at the end.
ghostdog74
A: 

To save the results to a csv file modify ghostdog74's code as follows.

Set objFS=CreateObject("Scripting.FileSystemObject")
WScript.Echo Chr(34) & "Full Path" &_
 Chr(34) & ","  & Chr(34) & "File Size" &_
 Chr(34) & ","  & Chr(34) & "File Date modified" &_
 Chr(34) & "," & Chr(34) & "File Date Created" &_
 Chr(34) & "," & Chr(34) & "File Date Accessed" & Chr(34)
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
  If objDIR <> "\System Volume Information" Then
    For Each eFolder in objDIR.SubFolders
        Go eFolder
    Next   
  End If
    For Each strFile In objDIR.Files
        WScript.Echo Chr(34) & strFile.Path & Chr(34) & "," &_
        Chr(34) & strFile.Size & Chr(34) & "," &_
        Chr(34) & strFile.DateLastModified & Chr(34) & "," &_
        Chr(34) & strFile.DateCreated & Chr(34) & "," &_
        Chr(34) & strFile.DateLastAccessed & Chr(34)
    Next 
End Sub 

Then call it from the command line like this.

c:\test> cscript //nologo myscript.vbs "c:\" > "C:\test\Output.csv"
Tester101
A: 

Hi Guys, I have tried this code and noticed that when its run, and a protected file is processed the script stops ‘permission denied’ , for example a system file even though I am logged in as an administrator.

Is there a way to make it avoid such files or to pass them instead of it stopping completely.

Please advice and help if possible.

Thank you

On Behalf of Khalid

MalsiaPro