File Size and Date

Posted on 2003-03-11
Medium Priority
Last Modified: 2010-05-01
I've got the following code in my programm:

m_strFilePath = File2.Path & "\" & "List.txt"
  Open m_strFilePath For Output As #1
  For intIndex = 0 To File2.ListCount - 1
       Print #1, File2.List(intIndex)
  Next intIndex
  Close #1
End If

This writes a list.txt in the directory where all the files are, with the files that are in the same directory.
Now my questions is how to ad to this procedure a way to get the filesize an date, and add that to the same file like:
goodmorning.jpg     12323     12/07/2003
               ^^^^^     ^^^^^ These should be spaces or tabs

Is it possible to do that?
And could you give a code example?

Kind Regards, Joleen.
Question by:Joleen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8114894
check out this code:

put this on a module:

Option Explicit

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Public Type WIN32_FIND_DATA
 dwFileAttributes  As Long
 ftCreationTime    As FILETIME
 ftLastAccessTime  As FILETIME
 ftLastWriteTime   As FILETIME
 nFileSizeHigh     As Long
 nFileSizeLow      As Long
 dwReserved0       As Long
 dwReserved1       As Long
 cFileName         As String * 100
 cAlternate        As String * 14
End Type

Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
  (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

and put this on a new proyect's main form:

Private Sub Form_Load()
Dim filedata As WIN32_FIND_DATA
Dim retval As Double
retval = FindFirstFile("c:\autoexec.bat", filedata)
MsgBox filedata.nFileSizeLow
End Sub

make some experients and enjoy!!!!
LVL 34

Expert Comment

ID: 8114896
Look at FileDateTime() function in help.

Basically, you call the function with the filename and path:

m_strFilePath = File2.Path & "\" & "List.txt"
 Open m_strFilePath For Output As #1
 For intIndex = 0 To File2.ListCount - 1
      Print #1, File2.List(intIndex) & " " & filedatetime(file2.list(intindex))
 Next intIndex
 Close #1
End If

There is a very CLEAR example in the VB help.....

LVL 38

Accepted Solution

PaulHews earned 200 total points
ID: 8114938
Open m_strFilePath For Output As #1
For intIndex = 0 To File2.ListCount - 1
    Print #1, File2.List(intIndex), FileLen(File2.Path & "\" & File2.List(intIndex)), Format(FileDateTime(File2.Path & "\" & File2.List(intIndex)), "mm/dd/yyyy")
Next intIndex
Close #1

Author Comment

ID: 8115217
I do not understand how you created the spaces in the lines, can you explain that?
For the other guys, thank you very much, it triggers al lot of idea's, but I have to reward PaulHews, because his solution worked instantly.
LVL 38

Expert Comment

ID: 8115413
If I do this:

Print #1, x, y, z

then the print statement will print the variables x, y and z in the file with a tab character separating them.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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