Results 1 to 5 of 5

Thread: Copying files into an array??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    I have a folder with many files of different types in it. I need to know how would I copy each filename and the file size into an array. Then I want to copy files with a certain extension over to a different folder and Verify that from the file attributes that the files copied over are the same size etc. as the origional files.
    If anyone has some code or some suggestions on how to do this I would really appreciate it. Thanks a lot for your help.
    JK

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    This example loads all the filenames in "D:\" into the variable FileNames(), at the same time copying the text files in "D:\" into "D:\Temporary".

    Code:
    Dim FileNames(), i, temp, MyPath, Ext
    Sub Test()
    ReDim FileNames(0)
    MyPath = "D:\"
    temp = Dir(MyPath)
    
    Do
        temp = Dir
        If temp <> "" Then
            i = i + 1
            ReDim Preserve FileNames(i)
            FileNames(i) = temp
            Ext = UCase(Mid(temp, InStr(1, temp, ".") + 1, 3))
            If Ext = "DLL" Then
                FileCopy MyPath & temp, "D:\Temporary\" & temp
            End If
        End If
    Loop Until temp = ""
    
    End Sub
    Hope that helps.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    That's great, thanks a lot. Any idea on how to compare the size of the files in the origional folder to the size of the files in the new folder. Thanks again

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Talking

    Should be easy, here you can use EnumDir sub to populate stringarrays with the files in a directory. Use filelen to get the size or a file
    Code:
    Sub EnumDir(Byref edir() as string,path as string)
    Dim n as integer, a as string
     A=Dir(path)
     Do while len(A)
       Redim preserve edir(n)
       edir(n)=A
       n=n+1
       A=DIR
      Loop
    end sub
    
    Sub main()
    Dim olddir() as string,newdir() as string
      enumdir olddir(),"D:\"
      enumdir newdir(),"D:\Newdir"
      for n=0 to ubound(olddir)
        if filelen(olddir(n))=filelen(newdir(n)) then 
          'files are the same size
        end if
      next n
    end sub
    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Thanks a lot guys

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