Results 1 to 3 of 3

Thread: long file name retrieval

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    25

    Exclamation

    I am looking for a way to copy long filenames from windows explorer, and paste them into excel. For instance i would like to be able to copy all the file names in an entire directory, and then paste them as text. Any ideas?

    thanks in advance

    badhaiku

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Dir function returns long names, You pass the path the first time and returns the rest of the files each time call dir until you get "" in return
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    Using kedaman's idea:
    Code:
    Option Base 1
    
    Private Sub SendToExcel(Files)
    Dim x As Excel.Application
    Dim objSheet As Excel.Worksheet
    Set x = CreateObject("Excel.Application") ' create object
    Set objSheet = x.Workbooks.Open(App.Path & "\MyXls.xls").ActiveSheet  'open the workbook
    For i = 1 To UBound(Files)
        objSheet.Cells(i, 1).Value = Files(i) 'write to excel
    Next
    objSheet.Columns(1).AutoFit 'fit the column
    x.Visible = True 'show excel
    Set objSheet = Nothing 'free memory
    Set x = Nothing
    
    End Sub
    Private Function GetFileNames(Folder As String)
    Dim Vals()
    Dim TotalFiles As Integer
    Dim CurrentFile As String
    Dim i
    CurrentFile = Dir(Folder)  'get first file
    Do While CurrentFile <> "" 'loop until end
        i = i + 1
        ReDim Preserve Vals(i) 'resize array
        Vals(i) = CurrentFile 'set value
        CurrentFile = Dir 'get new value
    Loop
    
    GetFileNames = Vals
    End Function
    
    '-------------------------------------------------------------------------------
    
    'Usage:
    Dim Files()
    Files = GetFileNames("C:\")
    
    SendToExcel (Files)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width