Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Directory Information... 1

Status
Not open for further replies.

zenenigma

Programmer
Apr 23, 2001
119
US
I track file sizes that come in on my company's server. The problem is, the weekend staff does not always track the size, and the Lan-Ops group archives the files before I can get the file size.

I run an access process everyday (the weekend staff runs it as well), to explain what has been done for the day. Is there any kind of ActiveX/OCX control or process I can attach to my current process to import or copy the details of a few folders. I'd need to know file names and file sizes within a single level directory. I've seen several stand alone programs which I'm sure I won't be able to get the staff to run. I've also realize there is a FileListBox control, but it doesn't look like there's a way to take a snapshot of it.

If anyone has any possible solutions they would be greatly appreciated. The programmers that are working on our main product are looking into ways of tracking the file size through processing, but haven't yet found a solution.
 
You can use the FileSystemObject to gather the data you need. (Access2K and AccessXP) John Ruff - The Eternal Optimist :)
 
Thanks for the tip, John. I've been playing around with the commands, but I (and everyone in the office) is still using Access 97. Also, when I tell it to get the information, it will only pull up the first file it finds that meets the criteria, rather then all files that meet it.

What I'd like to do is get all the records (consisting of file name and file size) and append them into an ongoing table. But I'm not quite sure how to do that with Access 97 and the FileSystem Object command that is new to me.

Any help from anyone would be appreciated.

Thanks again John
 
Well I've been able to get the information I need using the Dir, GetAttr, and FileLen commands. I also have a loop made. So when I check it in the debug window it looks very nice, file then file size. How do I put it into a table? Blech!

my code so far:
---------------------------------------
Dim filename as string
Dim filepath as string
Dim filelength as integer
------------------------------------------
filepath = "C:\Directory\Data Files\"
filename = Dir("C:\Directory\Data Files\*.txt")

Do While filename <> &quot;&quot;

If (GetAttr(filepath & filename) And vbNormal) = vbNormal Then
Debug.Print filename
Debug.Print FileLen(filepath & filename) / 1000
End If
filename = Dir
Loop

---------------------------------------
I'd like to have it in a table with 2 fields (possibly 3 if I'd like a date stamp). I'm sure I probably need to put it in the loop somewhere, but I'm totally lost.

 
' Make sure you have a reference to the
' Microsoft DAO x.x Object Library

Dim filename as string
Dim filepath as string
Dim filelength as integer
' New
Dim rs as dao.recordset

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

' New
set rs= currentdb.openrecordset(&quot;YourTableName&quot;)

filepath = &quot;C:\Directory\Data Files\&quot;
filename = Dir(&quot;C:\Directory\Data Files\*.txt&quot;)

Do While filename <> &quot;&quot;

If (GetAttr(filepath & filename) And vbNormal) = vbNormal Then
' Add data to table
rs.addnew
rs!FileName=filename
rs!FileLen=FileLen(filepath & filename) / 1000
rs!Update
Debug.Print filename
Debug.Print FileLen(filepath & filename) / 1000
End If
filename = Dir
Loop

' New
' Close the recorset
rs.close
' Release all resources
set rs=nothing John Ruff - The Eternal Optimist :)
 
John, everything has worked out great. Thanks so much for your help. I've thrown the whole thing into a function, keep the table in our tracking database, link the table to our nightly process (where the function is), and it (should) update everynight. I had a little trouble with the rs!Update until I went into the Access Help files and they suggested rs.Update, so everything works fine. Thanks again for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top