473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Table to include folders in a directory - Multilevel

Hi,
I have seen some of the threads but and looking to create a table in Access 2003 with the following information

Address / File / Type / size /
C: / Access / Folder / 375KB
C: / TableExcel.xls / xls or excel. / 200 KB
C:Access / Test2Access.Mdb / mdb or access / 200Kb
C:Access / TestAccess.Mdb / mdb or access / 50 Kb
C:Access / Templates / Folder / 100KB

I wont my table to include all folders and files in both C and D drive.

Is this possible. If so can u give me a program to do the same. I am a novice to Acess.

THanks for ur help and Support
Nov 13 '09 #1
10 3046
NeoPa
32,556 Expert Mod 16PB
We don't provide solutions here George. We help you to learn how to do it yourself. If you're interested we can do a certain amount of hand-holding.

What you talk about is certainly possible. You would need to be clearer exactly what you are looking to do. This could all be quite involved you understand (sounds like it may be quite fun though, if you're up for it).
Nov 15 '09 #2
Thanks NeoPa for your response.
Sorry if I sounded like I wanted a solution. I actually wanted to learn how I could achieve the following.
Really what I am looking to achieve is a code that could create a table. The table is to include all files/folder that are currently located in C: drive multilevel)The table should have the following field.
Address: this is the address - for example: C:/Access
File/Folder name - This is all the files/folders that exist in this folder
Type - states the extension (.mdb, .xls or if it is a folder)
Size - states the size of the item.

So far I have managed to do the code below. This basically brings out all files and folders stored in my C drive. I am looking for help to extract the other fields and make it multilevel. And ofcourse if possible a Link that will take me directly to the folder address. Hope u could teach/help me.
Expand|Select|Wrap|Line Numbers
  1. Sub InsertDirectories()
  2.     Dim DirectoryName
  3.     Dim sql
  4.  
  5.     DirectoryName = Dir("C:\", vbDirectory)
  6.     Do Until DirectoryName = ""
  7.         If DirectoryName <> "." And DirectoryName <> ".." Then
  8.  
  9.             sql = "INSERT INTO TBL1 ( Name ) " & _
  10.                 "SELECT '" & DirectoryName & "' AS Directory"
  11.             CurrentProject.Connection.Execute sql
  12.         End If
  13.         DirectoryName = Dir
  14.     Loop
  15. End Sub
Nov 19 '09 #3
ChipR
1,287 Expert 1GB
To get further information about the files, you will probably need to use the FileSystemObject. See Scripting Run-Time Reference on MSDN and Microsoft Scripting Runtime #1 from the Insights section here on Bytes.
Nov 19 '09 #4
NeoPa
32,556 Expert Mod 16PB
Well, first of all you need to understand that because Dir() can only work relative to the previous call, it is not going to be straightforward to populate this table in a simple, recursive, fashion. Secondly, of course, Chip is right about needing something else to return the size values of the files. It is possible to determine this by opening the file, but this is time-consuming and the better approach seems to be to use the FileSystemObject as he suggests.

With this in mind, and understanding that this FileSystemObject also has a means whereby you can determine the files in the structure too (probably easier to work with too than the Dir() function), it seems appropriate to ignore Dir() entirely and look at a completely FileSystemObject based solution.

First you need a reference to the "Windows Script Host Object Model".

I have knocked up some code to start you off with. It simply trawls through from the point you enter and displays the values you're after in the Immediate Pane of the debugger. The code isn't very long, and I've included the database as an attachment for you to have a play around with.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdTrawl_Click()
  5.     Dim fso As FileSystemObject
  6.     Dim fld As Folder
  7.  
  8.     Set fso = CreateObject("Scripting.FileSystemObject")
  9.     Set fld = fso.GetFolder(FolderPath:=Me.txtRoot)
  10.     Call DoFolder(fld)
  11. End Sub
  12.  
  13. Private Sub DoFolder(fldParent As Folder)
  14.     Dim fld As Folder
  15.     Dim fil As File
  16.  
  17.     With fldParent
  18.         Debug.Print .Path
  19.         For Each fld In .SubFolders
  20.             Call DoFolder(fldParent:=fld)
  21.         Next fld
  22.         For Each fil In .Files
  23.             With fil
  24.                 Debug.Print .ParentFolder, .Name, .Type, .Size
  25.             End With
  26.         Next fil
  27.     End With
  28. End Sub
  29.  
  30. Private Sub cmdExit_Click()
  31.     Call DoCmd.Close
  32. End Sub
Attached Files
File Type: zip FileSystem.Zip (63.8 KB, 114 views)
Nov 19 '09 #5
NeoPa
32,556 Expert Mod 16PB
Just as I was waking up this morning it occurred to me that something I'm doing at work atm could benefit directly from a database structure such as the one you describe (with maybe a few more fields populated). I will see if I can come up with something more complete and post it. Perhaps as an article. Watch this space.
Nov 21 '09 #6
NeoPa
32,556 Expert Mod 16PB
While exploring in this area I noticed something I feel I ought to share :
The Size property of a folder is calculated at the time by trawling through all the contained files and subfolders (and their files and subfolders (etc.)). Generally to be avoided as :
  1. It can take an extraordinarily long time.
  2. It is likely (particularly on any system drive) to come across files or folders that have been protected and access denied. In this case it trundles along seemingly forever, only to fail to provide a result in the end anyway.
Nov 21 '09 #7
NeoPa
32,556 Expert Mod 16PB
Another, related, thread can be found at Automatic update of excel spreadsheet.
Nov 21 '09 #8
NeoPa
32,556 Expert Mod 16PB
I'm just playing with a version that I've prepared for work. I've found out much about file usage that I wouldn't have guessed :
  1. File Types > 50 chars long. Will need to increase
  2. Full pathnames longer than 255 (even though this has always been published as a practical limit I believe). As this is pretty fundamental to linking files to their holding folders, Memo fields are not an option. I've had to truncate to 255 instead.
  3. Sizes larger than can fit in a 32-bit Long Integer - No great surprise I suppose nowadays. I have had to handle this by showing and storing values as Bytes, through KiloBytes, MegaBytes, etc to YottaBytes (1024 ^ 8), as and when required.
  4. Data drives are ok, but anything with security applied (almost all System drives) causes the code to stop dead in its tracks. Not even allowing continuation by ignoring the secure folders.
All in all a bit more work to do :(
Nov 22 '09 #9
Great i will wait for ur article. I hope it helps me. Please do let me know once u get there. Thanks once again
Nov 23 '09 #10
NeoPa
32,556 Expert Mod 16PB
I wouldn't recommend that George. I first have to produce a working database for work, which may take a fair while. After that I will only get a chance to put it into language fit for an article when I have a chunk of time to spare. That may be months.

Besides, this really isn't about someone doing it for you. It's about your looking at an example, with any helpful comments too, and playing with it yourself to produce your own thing. I will post what I have already as it will certainly be more of the basics done for you, but that's all I plan on for now.
Attached Files
File Type: zip FileSystem.Zip (72.8 KB, 146 views)
Nov 23 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: mark | last post by:
IF I have something like this: <title><?php print($pagetitle); ?></title> <body> <?php include("folders/my_include.php"); ?> </body> </html> and my_include.php contains the value to the...
1
by: Kris | last post by:
Question: How do you create an Installer program using the Package and Deployment Wizard provided by Visual Studio Pro 6.0 (SP5) to include subfolders and their contents. I understand how to...
7
by: MrNobody | last post by:
I was a Java developer so I'm used to using property files as a means to keep configuration settings for my apps. I'm wondering what options are there with ..NET? Some settings I want to include...
0
by: Francois | last post by:
Hi, I think I found a bug with VS, and I've included a project example of the problem I got. I've got a project deep into a set of folders. The project have an additional include library...
1
by: Øyvind Isaksen | last post by:
I try to find som information about creating folders (and subfolders) on the webserver using asp.net (1.0). I have made a filuploader, and all files are now saved in the same folder on the...
26
by: Jan Engelhardt | last post by:
Hello, assume foo/bar.h exists, and is included as '#include "bar.h"' in foo/bar.c. `gcc -c foo/bar.c` will compile it fine (i.e. finds the file). Is this a gcc extension or a C compiler...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
5
by: =?ISO-8859-2?Q?=A3ukasz_Z?= | last post by:
hello, Is there any way to include directory in program eg. #include <Qt> where a Qt is a directory I have exactly such problem I download source code and I can not compile it, because...
3
by: =?Utf-8?B?VG9kZCBEb2JtZXllcg==?= | last post by:
I am working on developing a program using Visual Studio 2003 but am having problems getting my program to find my GL.h and GLU.h, and I am guessing it will have the same problems trying to link to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.