Copy directory list to text file 
Author Message
 Copy directory list to text file

I can anyone show me some code on how read the directory not the sub
directory from a CD I know how find the CD but not how to read the CD
directory list and how to save it to file. I am only 12 years old and
this is my first try at VB.

Code for getting the CD-Rom drive letter (Below).

Public Function GetDriveListing() As String()
    Dim sDrives As String        
    sDrives = String(255, 0)
    Dim x() As String
    GetLogicalDriveStrings 255, sDrives
    sDrives = Mid(sDrives, 1, InStrRev(sDrives, "\"))
    Dim tmp() As String
    tmp = Split(sDrives, Chr(0))
    Dim y As Long
    For y = 0 To UBound(tmp)        
    If GetDriveType(tmp(y)) = DRIVE_CDROM Then
    ReDim Preserve x(0 To y)
     x(y) = tmp(y)
     End If
    Next y
    GetDriveListing = x
End Function

Any help whould be great.
--
Rick



Sat, 12 Nov 2005 23:58:12 GMT  
 Copy directory list to text file
Hm, i would recommend to use the microsoft scripting runtime ( by linking
the Programm to it ... unfortunately I don't know how this is called in VB
English...)

If you manage to do this although I tried to describe it ;) you may work
with the following code :

All that you need beside it is a Listbox, a commandbutton and a drivelist,
but it should be easy tu fix this to suit it to your project.

The Only thing that i should note at the end is, that this Programm does
recurse EVERY subfolder ...

Bye
Wind...

Code :

Option Explicit
Dim FSO As FileSystemObject
Private Sub cmdGO_Click()
  Dim sPath As String
  List1.Clear

  ' Init FSO
  Set FSO = New FileSystemObject

  ' Start...
  Screen.MousePointer = vbHourglass
  sPath = Left$(Drive1.drive, 2)
  FSO_GetAllFolders List1, sPath
  Screen.MousePointer = vbNormal
End Sub

' Recursive function to get all folders and subfolders
Private Sub FSO_GetAllFolders(Liste As ListBox, _
  ByVal sPath As String)

  Dim Folder As Folder
  Dim SubFolder As Folder

  ' If possible - add a backslash
  If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"

  Set Folder = FSO.GetFolder(sPath)
  Liste.AddItem sPath

  ' Ignore a possible Access Error
  On Local Error Resume Next

  ' Read Subfolders
  If Folder.SubFolders.Count > 0 Then
    For Each SubFolder In Folder.SubFolders
      FSO_GetAllFolders Liste, sPath & SubFolder.Name
    Next
  End If
End Sub



Sun, 13 Nov 2005 00:42:50 GMT  
 Copy directory list to text file

Quote:

>I can anyone show me some code on how read the directory not the sub
>directory from a CD I know how find the CD but not how to read the CD
>directory list and how to save it to file. I am only 12 years old and
>this is my first try at VB.

Option Explicit

Private Const ThePath = "c:\windows"

Private Sub Command1_Click()
    Dim A$()

    Call LS_GetFilesInPath(ThePath$ + "\*.exe", A$())
    ' ---
    Me.Print UBound(A$()); " Files in A$()"
    Me.Print A$(1)
    Me.Print A$(2)

End Sub

Private Sub LS_GetFilesInPath(FileSpec$, A$())
    Dim S$, Max%, ArSize%

    ArSize = 0
    S$ = Dir(FileSpec$)
    While Len(S$)
          Max = Max + 1
          If Max > ArSize Then
             ArSize = ArSize + 100
             ReDim Preserve A$(ArSize)
          End If
          A$(Max) = S$
          S$ = Dir
    Wend
    ' --- Final Resize
    ' - Note: A$(0) is unused and undefined
    ReDim Preserve A$(Max)
End Sub



Sun, 13 Nov 2005 01:46:41 GMT  
 Copy directory list to text file
See the Dir$ function help and example...
Quote:

> I can anyone show me some code on how read the directory not the sub
> directory from a CD I know how find the CD but not how to read the CD
> directory list and how to save it to file. I am only 12 years old and
> this is my first try at VB.

> Code for getting the CD-Rom drive letter (Below).

> Public Function GetDriveListing() As String()
>     Dim sDrives As String
>     sDrives = String(255, 0)
>     Dim x() As String
>     GetLogicalDriveStrings 255, sDrives
>     sDrives = Mid(sDrives, 1, InStrRev(sDrives, "\"))
>     Dim tmp() As String
>     tmp = Split(sDrives, Chr(0))
>     Dim y As Long
>     For y = 0 To UBound(tmp)
>     If GetDriveType(tmp(y)) = DRIVE_CDROM Then
>     ReDim Preserve x(0 To y)
>      x(y) = tmp(y)
>      End If
>     Next y
>     GetDriveListing = x
> End Function

> Any help whould be great.
> --
> Rick



Sun, 13 Nov 2005 01:59:19 GMT  
 Copy directory list to text file

Quote:
> Hm, i would recommend to use the microsoft scripting runtime ( by linking
> the Programm to it ... unfortunately I don't know how this is called in VB
> English...)

. . . and how would you get this scripting runtime code of yours to run on
systems where scripting has been deliberately removed and/or disabled for
security reasons?

Mike



Sun, 13 Nov 2005 02:53:21 GMT  
 Copy directory list to text file
This can be removed ?
Oh, didn't know that ... good to know...

Thanks.


Quote:


> > Hm, i would recommend to use the microsoft scripting runtime ( by
linking
> > the Programm to it ... unfortunately I don't know how this is called in
VB
> > English...)

> . . . and how would you get this scripting runtime code of yours to run on
> systems where scripting has been deliberately removed and/or disabled for
> security reasons?

> Mike



Sun, 13 Nov 2005 13:17:17 GMT  
 Copy directory list to text file


Quote:
> This can be removed ?
> Oh, didn't know that ... good to know...
<snipped/>

> > . . . and how would you get this scripting runtime code of yours to run
on
> > systems where scripting has been deliberately removed and/or disabled
for
> > security reasons?

Not only "*can* be removed", but *should* be removed.
The Scripting runtime is *the* only reason script/macro
viruses are able to run.

Most large-scale companies remove it from the workstations
to avoid problems.

--
Dag.



Sun, 13 Nov 2005 16:37:07 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Selecting files in many directories, use of file list box

2. Directory Listing of files to include files in the subdirectories

3. Copying a text file into a large text box

4. Copy a directory and all sub-directories

5. How can I copy an mdb file to a new directory

6. Copying files from one directory to another

7. copying all files and subfolders in a directory?

8. Directory/File structure copy?

9. copying files to a directory

10. Copying a couple of files to a specific directory

11. Copying a couple of files to a specific directory

12. Copying Files/Directories

 

 
Powered by phpBB® Forum Software