Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RaY RaY is offline
external usenet poster
 
Posts: 164
Default need subdirectory check 99

The following code writes the contents (directories and files) into a text
file. It indents directories then places the filenames in line beneath that
directory. When it encounters another directory it indents again. The problem
I have is I do not know how to check if the directory is a SUB directory?
Onces the program hits a new parent directory I would like to reset the tab
to 0. The resulting print would be formatted like windows explorer listing
with subdirectories incrementally tabbed beneath its parent directory and all
parent directories to have no indentation.

Bottom line I need a method to check if property a subdirectory. Current
code shown below:

txtfile = "c:\temp\List2.txt"
Filenum = FreeFile
numfiles = 1
tabbed = 1
Open txtfile For Output Access Write As Filenum
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
myname = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While myname < "" ' Start the loop.

' Ignore the current directory and the encompassing directory.
If myname < "." And myname < ".." Then

' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & myname) And vbDirectory) = vbDirectory Then
tabbed = tabbed + 1
Print #Filenum, Tab(tabbed); "--"; myname
Else
Print #Filenum, Tab(tabbed + 4); myname
End If ' it represents a directory.
End If
myname = Dir ' Get next entry.
Loop
Close #Filenum


--
Ray
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default need subdirectory check 99

I believe you are mistaken on what your code is doing
Your code works on a single directory. In this case "C:\"

It will list the subdirectories "C:\" and files in "C:\"

It does not list the files for any subdirectories found in that directory.

The way you have your Tabbed variable set up should make a progressive
indent, but it is meaningless.

http://msdn.microsoft.com/library/de...ce09072000.asp
Working with Files, Folders, and Drives: More VBA Tips and Tricks
by David Shank (Office talk)




http://support.microsoft.com/kb/185476/EN-US/
How To Search Directories to Find or List Files

http://support.microsoft.com/kb/185601/EN-US/
HOW TO: Recursively Search Directories by Using FileSystemObject

http://support.microsoft.com/kb/186118/EN-US/
How To Use FileSystemObject with Visual Basic


Jim Rech posted recently posted some code that Bill Manville wrote.


Here's a link:


http://groups.google.com/groups?thre...%40tkmsftngp11

--
Regards,
Tom Ogilvy



"Ray" wrote:

The following code writes the contents (directories and files) into a text
file. It indents directories then places the filenames in line beneath that
directory. When it encounters another directory it indents again. The problem
I have is I do not know how to check if the directory is a SUB directory?
Onces the program hits a new parent directory I would like to reset the tab
to 0. The resulting print would be formatted like windows explorer listing
with subdirectories incrementally tabbed beneath its parent directory and all
parent directories to have no indentation.

Bottom line I need a method to check if property a subdirectory. Current
code shown below:

txtfile = "c:\temp\List2.txt"
Filenum = FreeFile
numfiles = 1
tabbed = 1
Open txtfile For Output Access Write As Filenum
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
myname = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While myname < "" ' Start the loop.

' Ignore the current directory and the encompassing directory.
If myname < "." And myname < ".." Then

' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & myname) And vbDirectory) = vbDirectory Then
tabbed = tabbed + 1
Print #Filenum, Tab(tabbed); "--"; myname
Else
Print #Filenum, Tab(tabbed + 4); myname
End If ' it represents a directory.
End If
myname = Dir ' Get next entry.
Loop
Close #Filenum


--
Ray

  #3   Report Post  
Posted to microsoft.public.excel.programming
RaY RaY is offline
external usenet poster
 
Posts: 164
Default need subdirectory check 99

Thanks. The code I left is doing what I want except I need a control to
indicate when to reset the tab. I realize now that all directories are
subdirectories of the parent C: so a simple property check for subdirectories
will not work. Thanks again and I will review the link you provided.


--
Ray


"Tom Ogilvy" wrote:

I believe you are mistaken on what your code is doing
Your code works on a single directory. In this case "C:\"

It will list the subdirectories "C:\" and files in "C:\"

It does not list the files for any subdirectories found in that directory.

The way you have your Tabbed variable set up should make a progressive
indent, but it is meaningless.

http://msdn.microsoft.com/library/de...ce09072000.asp
Working with Files, Folders, and Drives: More VBA Tips and Tricks
by David Shank (Office talk)




http://support.microsoft.com/kb/185476/EN-US/
How To Search Directories to Find or List Files

http://support.microsoft.com/kb/185601/EN-US/
HOW TO: Recursively Search Directories by Using FileSystemObject

http://support.microsoft.com/kb/186118/EN-US/
How To Use FileSystemObject with Visual Basic


Jim Rech posted recently posted some code that Bill Manville wrote.


Here's a link:


http://groups.google.com/groups?thre...%40tkmsftngp11

--
Regards,
Tom Ogilvy



"Ray" wrote:

The following code writes the contents (directories and files) into a text
file. It indents directories then places the filenames in line beneath that
directory. When it encounters another directory it indents again. The problem
I have is I do not know how to check if the directory is a SUB directory?
Onces the program hits a new parent directory I would like to reset the tab
to 0. The resulting print would be formatted like windows explorer listing
with subdirectories incrementally tabbed beneath its parent directory and all
parent directories to have no indentation.

Bottom line I need a method to check if property a subdirectory. Current
code shown below:

txtfile = "c:\temp\List2.txt"
Filenum = FreeFile
numfiles = 1
tabbed = 1
Open txtfile For Output Access Write As Filenum
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
myname = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While myname < "" ' Start the loop.

' Ignore the current directory and the encompassing directory.
If myname < "." And myname < ".." Then

' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & myname) And vbDirectory) = vbDirectory Then
tabbed = tabbed + 1
Print #Filenum, Tab(tabbed); "--"; myname
Else
Print #Filenum, Tab(tabbed + 4); myname
End If ' it represents a directory.
End If
myname = Dir ' Get next entry.
Loop
Close #Filenum


--
Ray

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Subdirectory in "Default User" App Data pagates Excel Programming 5 August 3rd 06 04:16 PM
searching for a worksheet name while going through a subdirectory ibbm Excel Programming 2 March 27th 06 09:12 PM
Return most recent file in subdirectory with out using FileSearch Enohp Aikon Excel Programming 20 October 3rd 05 11:24 PM
Saving to subdirectory using date() pvm3911 Excel Programming 1 August 24th 05 07:27 AM
Find Correct Subdirectory Stratuser Excel Programming 1 November 15th 04 11:56 PM


All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"