Search : in
By :

Get filenames & timestamps batch file

Last answer on Nov 4, 2009 12:57:48 am GMT mhel_0414, on Sep 12, 2009 8:15:01 am BST 
 Report this message to moderators

Hello,
Can anyone help me create a batch file that will display all the files, subfolders and files under subfolders of folder with both date created and date modified then output the result to .txt or .xls file.

Here's what I've tried but I cannot display both date created and date modified.

dir /t:c /t:w /s /q "C:\Documents and Settings\administrator\Desktop\fileinfo_test" >> "C:\Documents and Settings\administrator\Desktop\dir.txt"

Please help me with this.
Thank you in advance..

mhel

Configuration: Windows XP Internet Explorer 6.0

Best answers for « get filenames & timestamps batch file » in :
[Batch File]Time based actions Show[Batch File]Time based actions Issue Solution Issue Upon creating a batch file you want that certain line of batch file is executed after every second (not all the program only certain line). In VB we can do it using the Timer...
Batch file – Get Filenames & Timestamps ShowBatch file – Get Filenames & Timestamps Issue Solution Note Issue Can anyone help me create a batch file that will display all the files, subfolders and files under subfolders of folder with both date created and date modified then...
What to do if a file cannot be deleted ShowWhat to do if a file cannot be deleted How to get rid of the file? Solution 1: Ensure that the file/folder is not in use Solution 2: Run your system on Safe Mode Solution 3: Download or update your Antivirus program Solution 4: Use...
File sharing in Windows XP ShowAdvantages File sharing involves making the content of one or more directories available through the network. All Windows systems have standard devices making it easy to share the content of a directory. However, file sharing may lead to security...

1

sharpman, on Sep 13, 2009 12:11:00 pm BST
  • +3

Ok, you were nearly there
============================================================­====

DIR [drive:][path][filename] [/A[[:]attributes]] /B /C /D /L /N
[/O[[:]sortorder]] /P /Q /S [/T[[:]timefield]] /W /X /4


[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4 Displays four-digit years

Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.

============================================================­======

dir "D:\Documents and Settings\dave\Desktop\"/T:C /T:W /S /Q >> "d:\Documents and

Settings\dave\Desktop\dir.txt"

me thinks will produce the desired result. (you need to put the switches after the source details.

hope that helps. give me a nod if it does.

Reply to sharpman

2

mhel_0414, on Sep 14, 2009 4:17:48 am BST

Thank you for the help sharpman but still, it doesn't show both the date created and date modified of the files..=(

Reply to mhel_0414

3

sharpman, on Sep 16, 2009 12:21:48 am BST
  • +1

I think you're limited in what dos can do in respect of what you are trying to do.

you can have date/time created or date/time accessed, but not both.

Reply to sharpman

4

sharpman, on Sep 16, 2009 12:39:02 am BST
  • +3

This will do what you want in an excel sheet. add it as a macro to your sheet, when run it will create a sheet with all the information that you require.

------------------------------------------------------------­---------------------------------------
Public X()
Public i As Long
Public objShell, objFolder, objFolderItem
Public FSO, oFolder, Fil

Sub MainExtractData()

Dim NewSht As Worksheet
Dim MainFolderName As String
Dim TimeLimit As Long, StartTime As Double

ReDim X(1 To 65536, 1 To 11)

Set objShell = CreateObject("Shell.Application")
TimeLimit = Application.InputBox("Please enter the maximum time that you wish this code to run for in minutes" & vbNewLine & vbNewLine & _
"Leave this at zero for unlimited runtime", "Time Check box", 0)
StartTime = Timer

' This is the part I need to change to create a Table with these field names.

Application.ScreenUpdating = False
MainFolderName = BrowseForFolder()
Set NewSht = ThisWorkbook.Sheets.Add

X(1, 1) = "Path"
X(1, 2) = "File Name"
X(1, 3) = "Last Accessed"
X(1, 4) = "Last Modified"
X(1, 5) = "Created"
X(1, 6) = "Type"
X(1, 7) = "Size"
X(1, 8) = "Owner"
X(1, 9) = "Author"
X(1, 10) = "Title"
X(1, 11) = "Comments"

' i is defined Publicly as a Long Integer
i = 1

Set FSO = CreateObject("scripting.FileSystemObject")
Set oFolder = FSO.GetFolder(MainFolderName)
'error handling to stop the obscure error that occurs at time when retrieving DateLastAccessed
On Error Resume Next
For Each Fil In oFolder.Files
Set objFolder = objShell.Namespace(oFolder.Path)
Set objFolderItem = objFolder.ParseName(Fil.Name)
i = i + 1
If i Mod 20 = 0 And TimeLimit <> 0 And Timer > (TimeLimit * 60 + StartTime) Then
GoTo FastExit
End If
If i Mod 50 = 0 Then
Application.StatusBar = "Processing File " & i
DoEvents
End If
X(i, 1) = oFolder.Path
X(i, 2) = Fil.Name
X(i, 3) = Fil.DateLastAccessed
X(i, 4) = Fil.DateLastModified
X(i, 5) = Fil.DateCreated
X(i, 6) = Fil.Type
X(i, 7) = Fil.Size
X(i, 8) = objFolder.GetDetailsOf(objFolderItem, 8)
X(i, 9) = objFolder.GetDetailsOf(objFolderItem, 9)
X(i, 10) = objFolder.GetDetailsOf(objFolderItem, 10)
X(i, 11) = objFolder.GetDetailsOf(objFolderItem, 14)
Next

'Get subdirectories
If TimeLimit = 0 Then
Call RecursiveFolder(oFolder, 0)
Else
If Timer < (TimeLimit * 60 + StartTime) Then Call RecursiveFolder(oFolder, TimeLimit * 60 + StartTime)
End If

FastExit:
Range("A:K") = X
If i < 65535 Then Range(Cells(i + 1, "A"), Cells(65536, "A")).EntireRow.Delete
Range("A:K").WrapText = False
Range("A:K").EntireColumn.AutoFit
Range("1:1").Font.Bold = True
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Range("a1").Activate

Set FSO = Nothing
Set objShell = Nothing
Set oFolder = Nothing
Set objFolder = Nothing
Set objFolderItem = Nothing
Set Fil = Nothing
Application.StatusBar = ""
Application.ScreenUpdating = True
End Sub

Sub RecursiveFolder(xFolder, TimeTest As Long)
Dim SubFld
For Each SubFld In xFolder.SubFolders
Set oFolder = FSO.GetFolder(SubFld)
Set objFolder = objShell.Namespace(SubFld.Path)
For Each Fil In SubFld.Files
Set objFolder = objShell.Namespace(oFolder.Path)
'Problem with objFolder at times
If Not objFolder Is Nothing Then
Set objFolderItem = objFolder.ParseName(Fil.Name)
i = i + 1
If i Mod 20 = 0 And TimeTest <> 0 And Timer > TimeTest Then
Exit Sub
End If
If i Mod 50 = 0 Then
Application.StatusBar = "Processing File " & i
DoEvents
End If
X(i, 1) = SubFld.Path
X(i, 2) = Fil.Name
X(i, 3) = Fil.DateLastAccessed
X(i, 4) = Fil.DateLastModified
X(i, 5) = Fil.DateCreated
X(i, 6) = Fil.Type
X(i, 7) = Fil.Size
X(i, 8) = objFolder.GetDetailsOf(objFolderItem, 8)
X(i, 9) = objFolder.GetDetailsOf(objFolderItem, 9)
X(i, 10) = objFolder.GetDetailsOf(objFolderItem, 10)
X(i, 11) = objFolder.GetDetailsOf(objFolderItem, 14)
Else
Debug.Print Fil.Path & " " & Fil.Name
End If
Next
Call RecursiveFolder(SubFld, TimeTest)
Next
End Sub

Function BrowseForFolder(Optional OpenAt As Variant) As Variant
'Function purpose: To Browser for a user selected folder.
'If the "OpenAt" path is provided, open the browser at that directory
'NOTE: If invalid, it will open at the Desktop level

Dim ShellApp As Object

'Create a file browser window at the default folder
Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

'Set the folder to that selected. (On error in case cancelled)
On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error GoTo 0

'Destroy the Shell Application
Set ShellApp = Nothing

'Check for invalid or non-entries and send to the Invalid error
'handler if found
'Valid selections can begin L: (where L is a letter) or
'\\ (as in \\servername\sharename. All others are invalid
Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
Case Else
GoTo Invalid
End Select

Exit Function

Invalid:
'If it was determined that the selection was invalid, set to False
BrowseForFolder = False

End Function

-------------------------------------------------------------------------------------------------

i know you wanted a dos script, but you're limited in what it can do.

hope this helps

Reply to sharpman

5

mhel_0414, on Sep 19, 2009 5:36:12 am BST

Hi sharpman,

Thank you very much for your help. It works perfectly as expected.
Thank you thank you thank you...
I really got limited knowledge in what dos commands can do but learning and studying right now.
Thanks again.

Reply to mhel_0414

6

sharpman, on Sep 20, 2009 12:19:55 pm BST

Your welcome mhel_0414

Reply to sharpman

7

 jamr_xx, on Nov 4, 2009 12:57:48 am GMT

Hi Sharpman,
How can I adjust this to check in multiple directories and only output files having a timestamp created today?

Thanks,
Jamr_xx

Reply to jamr_xx