-
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
-
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.
-
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
-
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
-