borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How to create a file selection dialog)Next Topic (Macro's in excel.. Help needed) New Topic New Poll Post Reply
AndreaVB Forum : VB General : file names
Poster Message
csmuley
Level: Guest


icon file names  Archived to Disk

My problem is that I want to copy all the filenames from a required folder to a word document. Please note I want to copy all the filenames from the folder one by one. So please suggest me how to use the folder command such as ListIndex, ListCount and Filename.

I am able to access the folder by getting path name etc. assigning a variable and inputbox.

20-05-2002 at 06:01 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: file names  Archived to Disk

Assuming you have a list control added, the following will put all the file names into the list box (just as an example to show how it's done).



Option Explicit

Private Sub Form_Load()
    Dim i As Integer
    
    For i = 0 To File1.ListCount - 1
        File1.ListIndex = i 'which item in list
        List1.AddItem File1.FileName 'Name selected
    Next
End Sub

[Edited by JLRodgers on 21-05-2002 at 11:17 AM GMT]

20-05-2002 at 07:52 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
csmuley
Level: Guest

icon Re: Re: file names  Archived to Disk

Thanks for your reply.

Please get my problem again, I want to copy the names of the files (from a particular given folder) and paste them in word document one by one. If possible in a table. I do not want to creat a ListBox.

Please suggest a solution.

Thanks Once again.
CS Muley

25-05-2002 at 07:56 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: file names  Archived to Disk

For any inserting or whatever, just replace the List1.AddItem with the code to where you want it put.

For a database table:

Private Sub DataBase()
    Dim i As Integer
    
    Dim adc As New ADODB.Connection
    Dim ars As New ADODB.Recordset
    
    Set adc = New ADODB.Connection
    Set ars = New ADODB.Recordset
    
    adc.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBaseName;Persist Security Info=False"
    ars.Open "[FileListNames]", adc, adOpenDynamic, adLockOptimistic
    
    
    For i = 0 To File1.ListCount - 1
        File1.ListIndex = i 'which item in list
        ars.AddNew
        ars.Fields("FileName") = File1.FileName 'Name selected
        ars.Update
    Next

    
    If ars.State = adStateOpen Then ars.Close
    If adc.State = adStateOpen Then adc.Close

    Set ars = Nothing
    Set adc = Nothing
End Sub


to insert into word or a file, it'd be similar to the first code; just once again, replacing the List1.Additem with the filename, or insert command for word.

25-05-2002 at 06:04 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
csmuley
Level: Guest

icon Re: Re: file names  Archived to Disk

Thanks for your kind suggestion. My problem is solved now.
Once again thanks for your quick reply.
CS Muley

quote:
JLRodgers wrote:
For any inserting or whatever, just replace the List1.AddItem with the code to where you want it put.

For a database table:

Private Sub DataBase()
    Dim i As Integer
    
    Dim adc As New ADODB.Connection
    Dim ars As New ADODB.Recordset
    
    Set adc = New ADODB.Connection
    Set ars = New ADODB.Recordset
    
    adc.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBaseName;Persist Security Info=False"
    ars.Open "[FileListNames]", adc, adOpenDynamic, adLockOptimistic
    
    
    For i = 0 To File1.ListCount - 1
        File1.ListIndex = i 'which item in list
        ars.AddNew
        ars.Fields("FileName") = File1.FileName 'Name selected
        ars.Update
    Next

    
    If ars.State = adStateOpen Then ars.Close
    If adc.State = adStateOpen Then adc.Close

    Set ars = Nothing
    Set adc = Nothing
End Sub


to insert into word or a file, it'd be similar to the first code; just once again, replacing the List1.Additem with the filename, or insert command for word.

29-05-2002 at 04:13 AM
| Quote Reply
AndreaVB Forum : VB General : file names
Previous Topic (How to create a file selection dialog)Next Topic (Macro's in excel.. Help needed) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder