473,385 Members | 1,642 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,385 software developers and data experts.

Saving Contents of a Dir to a .txt file

Hey, im only new, so please excuse me if i do something wrong.
But im making a program where all the program does is write EVERY file and EVERY folder name into a .txt file called "KMOD! Log.txt"

The program knows what directory to list, because the user of the program must navigate into the directory then press "Dump To Log File" to dump the contents into the log

Currently the ONLY code i have is::
Private Sub Command1_Click()
Open App.Path & "\log.txt" For Output As #1
Do While Dir1.ListIndex < Dir1.ListCount - 1
MsgBox.Dir1.Dir
Dir1.ListIndex = Dir1.ListIndex + 1
Loop
Close #1
End Sub
Jun 8 '07 #1
4 1775
debasisdas
8,127 Expert 4TB
Hi
Sgt D Pilla
Welcome to TSDN.

You have reached the right place for knowledge shairing.

Here you will find a vast resource of related topics and code.

Feel free to post more doubts/questions in the forum.

But before that give a try from your side and if possible try to post what/how you have approached to solve the problem.

It will help Experts in the forum in solving/underestanding your problem in a better way.

Please follow the posting guidelines in every new post/reply.

please do not expect complete code from the experts of the forum. try from user side ,if u are struck up some where then ask for help.
Jun 8 '07 #2
Hey, im only new, so please excuse me if i do something wrong.
But im making a program where all the program does is write EVERY file and EVERY folder name into a .txt file called "KMOD! Log.txt"

The program knows what directory to list, because the user of the program must navigate into the directory then press "Dump To Log File" to dump the contents into the log

Currently the ONLY code i have is::
Private Sub Command1_Click()
Open App.Path & "\log.txt" For Output As #1
Do While Dir1.ListIndex < Dir1.ListCount - 1
MsgBox.Dir1.Dir
Dir1.ListIndex = Dir1.ListIndex + 1
Loop
Close #1
End Sub
In this case you mean make a Search. this way is for begginers.
It's easy to export the objects' names and types ;)
1. Form:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type BrowseInfo
  4.     hWndOwner As Long
  5.     pIDLRoot As Long
  6.     pszDisplayName As String
  7.     lpszTitle As String
  8.     ulflags As Long
  9.     lpfnCallback As Long
  10.     lParam As Long
  11.     iImage As Long
  12. End Type
  13.  
  14. Private Const BIF_RETURNONLYFSDIRS = 1
  15. Private Const MAX_PATH = 260
  16. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
  17. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
  18. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
  19.  
  20. Public Function BrowseForFolder(ByVal hWndOwner As Long, ByVal sPrompt As String) As String
  21.     Dim iNull As Integer
  22.     Dim lpIDList As Long
  23.     Dim lResult As Long
  24.     Dim sPath As String
  25.     Dim udtBI As BrowseInfo
  26.  
  27.     With udtBI
  28.         .hWndOwner = hWndOwner
  29.         .lpszTitle = sPrompt
  30.         .ulflags = BIF_RETURNONLYFSDIRS
  31.     End With
  32.  
  33.     lpIDList = SHBrowseForFolder(udtBI)
  34.     If lpIDList Then
  35.         sPath = String$(MAX_PATH, 0)
  36.         lResult = SHGetPathFromIDList(lpIDList, sPath)
  37.         Call CoTaskMemFree(lpIDList)
  38.         iNull = InStr(sPath, vbNullChar)
  39.         If iNull Then
  40.             sPath = Left$(sPath, iNull - 1)
  41.         End If
  42.     End If
  43.  
  44.     BrowseForFolder = sPath
  45.  
  46.  
  47. End Function
  48. Private Sub cmdBrowse_Click()
  49. Dim sPath As String
  50.  
  51. txtPath.Text = ""
  52. sPath = BrowseForFolder(hWnd, "choose a directory")
  53. txtPath.Text = sPath
  54. End Sub
  55.  
  56. Private Sub cmdDisplay_Click()
  57.  
  58. 'declare variables ...
  59. Dim sPath As String
  60. Dim clsDirs As Collection
  61. Dim udcTraverse As cTraverseDirs
  62. Dim lCounter As Long
  63.  
  64. 'set user difened class and collections...
  65. Set clsDirs = New Collection
  66. Set udcTraverse = New cTraverseDirs
  67. 'get the path
  68. sPath = frmDirs.txtPath.Text
  69. If sPath = "" Then
  70.     MsgBox "You must select a path"
  71.     Exit Sub
  72. End If
  73. sPath = frmDirs.txtPath.Text & "\"
  74. 'add it to collection ...
  75. clsDirs.Add sPath
  76. 'initialize the counter ...
  77. lCounter = 1
  78. 'traverse call ...
  79. Call udcTraverse.TraverseDirectories(clsDirs, lCounter)
  80. End Sub
  81.  
and also it has a Class file:
Expand|Select|Wrap|Line Numbers
  1. Public Sub TraverseDirectories(ByVal clsDir As Collection, ByVal vCollectionCounter As Variant)
  2. On Error GoTo td_error:
  3.  
  4. Dim sDirName As String, sTempPath As String, sPathToTraverse As String
  5.  
  6.  
  7.     sPathToTraverse = clsDir.Item(vCollectionCounter)
  8.     sDirName = Dir(sPathToTraverse, vbDirectory)
  9.         Do While sDirName <> ""   ' Start the loop.
  10.             ' Ignore the current directory and the encompassing directory.
  11.             If sDirName <> "." And sDirName <> ".." Then
  12.                 ' Use bitwise comparison to make sure sDirName is a directory.
  13.                 If (GetAttr(sPathToTraverse & sDirName) And vbDirectory) = vbDirectory Then
  14.                     ' Display entry for directory...
  15.                     sTempPath = sPathToTraverse & sDirName & "\"
  16.                     clsDir.Add sTempPath
  17.                 Else
  18.                     'create a collection of all files ...
  19.                     frmDirs.lstDisplay.AddItem (sPathToTraverse)
  20.                     frmDirs.lstDisplay.AddItem (sDirName)
  21.  
  22.                 End If
  23.             End If
  24.             'Get next entry...
  25.             sDirName = Dir
  26.         Loop
  27.     vCollectionCounter = vCollectionCounter + 1
  28.     Call TraverseDirectories(clsDir, vCollectionCounter)
  29.     Exit Sub
  30. td_error:
  31.         'break out of the loop
  32.         Exit Sub
  33.  
  34. End Sub
  35.  
Jun 8 '07 #3
What does txtPath mean? and
txtPath.txt ?

is the txtPath a name of a controller ?
Jun 10 '07 #4
Acutally guys, dont worry about it.
I will do something else for my project. Its to difficult to get the program to write the name of every file in every folder in a certain directroy to a log file.
Jun 11 '07 #5

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

Similar topics

3
by: Martin Herrman | last post by:
Dear programmers, I have a form: <form action=".." method="post"> <textarea name="text1"></textarea> </form> And a php file that saves this variable to a file:
1
by: Bob Murdoch | last post by:
We have an asp application that creates reports from a database. The managers would like to create the report, view the results, add a comment, and save the report so that he can send a link to...
3
by: Aviv Ben-Yosef | last post by:
Hello all. I've been wondering whether or not there's a way to start writing to an ofstream and then save it under a specific filename, or must it be done in the first hand with fstream::open ?...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
3
by: jad101 | last post by:
I have an asp.net web page that: 1. Shows a message 2. Posts back (using javascript) 3. Reads contents of a file 4. response.write the contents of the file to the browser My issue is this: ...
8
by: Yu SONG | last post by:
Hi all, What would be the most efficient way to save an array of floats to a file (in text format)? At the moment, my code looks like: /* * Saving an array of floats to a file
3
by: vivicio047 | last post by:
i am writing a c prog in a Rich Text Box and want to save it. But saving the contents of the RTB also writes the font type,size and other details also as in an html file. please help me on how to...
14
by: Simon | last post by:
I'm trying to write a little function to save data. Basically I have a large 2d array of structs, so I'm going to have to call the save function once per struct in the array. I'd like to save the...
17
dbanning
by: dbanning | last post by:
I am trying to save the contents of a form as a bitmap and am unsure how to do this. I can use the savepicture command to save the form as a bitmap but the contents is not intact as you would expect....
6
by: John Kotuby | last post by:
Hi all, I am using a 3rd party program in a VS2005 web project. The tool takes as input a string containing HTML and converts it to RTF. I have been creating a page by dynamically loading...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.