|
-
Sep 15th, 2000, 09:25 AM
#1
Thread Starter
Addicted Member
I got this code as a reply to a previous thread. It's to take file names into an array and then compare the size of the old file to the size of the copied file in a diferent folder(The copying is done in another sub). I just can't seem to get it working. The files won't delete. Your help is greatlty appreciated.
Code:
'thanks to kedaman for the original 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 SizeChecking()
Dim olddir() As String, newdir() As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim n As Integer, a As String
EnumDir olddir(), "C:\TestOrator\Outgone\*.txt"
EnumDir newdir(), MyNewDir
For n = 0 To UBound(olddir)
If FileLen(olddir(n)) = FileLen(newdir(n)) Then
'files are the same size
MsgBox "files are the same size"
FSO.DeleteFile "C:\TestOrator\Outgone\*.txt"
Else
'files are not the same size
MsgBox "The Files that were transferred were not the same size."
End If
Next n
End Sub
Thanks
[Edited by kanejone on 09-15-2000 at 10:28 AM]
-
Sep 15th, 2000, 09:41 AM
#2
transcendental analytic
Actually i don't know how, you're using FSO (i'm not too familiar with it but vb has it's own command "Kill" and you'll get an error when you can't delete files with it.
BTW, this should be the 80000'th post on this forum
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.
-
Sep 15th, 2000, 09:51 AM
#3
Thread Starter
Addicted Member
Thanks for the reply kedaman. Even when I'm not using the FSO I can't even get the message box to appear. I'm wondering if it is possible to use the directory path in this way :EnumDir olddir(), "C:\TestOrator\Outgone\*.txt".
Thanks for your time
JK
Code:
Sub SizeChecking()
Dim olddir() As String, newdir() As String
Dim n As Integer, a As String
EnumDir olddir(), "C:\TestOrator\Outgone\*.txt"
EnumDir newdir(), MyNewDir
For n = 0 To UBound(olddir)
If FileLen(olddir(n)) = FileLen(newdir(n)) Then
'files are the same size
MsgBox "I can't get this message box to appear, any ideas"
Else
'files are not the same size
MsgBox "The Files that were transferred were not the same size."
End If
Next n
-
Sep 15th, 2000, 09:59 AM
#4
transcendental analytic
of course it works, that's what dir function is for.
try put a break on the if line and check out the values you get, if it doesn't break at all it's probably because there aren't any txt files in outgone, or also (and have you tested my Enumdir function enough?) there might be something wrong with enumdir, i didn't have access to vb when i wrote it 
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.
-
Sep 15th, 2000, 10:05 AM
#5
Thread Starter
Addicted Member
Sorry kedaman. I've only been at VB for three weeks now. How do I use dir??? Sorry if it's a stupid question
-
Sep 15th, 2000, 10:19 AM
#6
transcendental analytic
nono, my apologies, you probably don't know how to use kill either...
Enumdir takes care of dir, you just run my code instead, and tell me what you get in immediate window 
just copy and paste it here
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 SizeChecking()
Dim olddir() As String, newdir() As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim n As Integer, a As String
EnumDir olddir(), "C:\TestOrator\Outgone\*.txt"
EnumDir newdir(), MyNewDir
debug.print "files:" & Ubound(olddir) & "," & Ubound(newdir)
For n = 0 To UBound(olddir)
debug.print olddir(n) & " , " & newdir(n)
debug.print filelen(olddir(n)) & " , " & filelen(newdir(n))
If FileLen(olddir(n)) = FileLen(newdir(n)) Then
'files are the same size
MsgBox "files are the same size"
FSO.DeleteFile "C:\TestOrator\Outgone\*.txt"
Else
'files are not the same size
MsgBox "The Files that were transferred were not 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.
-
Sep 15th, 2000, 10:26 AM
#7
Thread Starter
Addicted Member
Thanks again for taking the time.
Here's what the immediate window has
files:19,91
New Text Document (10).txt , ADDSCCUS.DLL
-
Sep 15th, 2000, 10:40 AM
#8
transcendental analytic
got it!
You current directory is probably not C:\TestOrator\Outgone so i guess you don't get the filesize at all, but did you get any error anyhow?
You should replace
Code:
If FileLen(olddir(n)) = FileLen(newdir(n)) Then
with
Code:
If FileLen("C:\TestOrator\Outgone\*.txt"
& olddir(n)) = FileLen(mynewdir & newdir(n)) Then
note mynewdir should end with \ or you would have to add it in between
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.
-
Sep 15th, 2000, 10:43 AM
#9
Kedaman made a slight typo in his last reply.
This is the correct code:
Code:
If FileLen("C:\TestOrator\Outgone\"
& olddir(n)) = FileLen(mynewdir & newdir(n)) Then
Good luck!
-
Sep 15th, 2000, 10:54 AM
#10
Thread Starter
Addicted Member
Sorry I really must be wrecking your head at this stage. I really do appreciate it though. Here's my code in total so you can see what exactly I am trying to do. I still can't manage to delete the files from the outgone folder. Sorry about this
Code:
'added a public var for dirname
Public MyNewDir As String
Option Explicit
Private Function MakeFolder(newdir As String)
Dim dirname As String
dirname = "C:\TestOrator\"
newdir = dirname & newdir
ChDir dirname
If Dir(newdir, vbDirectory) <> "" Then
MsgBox "The Archiving Process has been started already. Please check the Correct folder to make sure."
Else
MkDir newdir
MyNewDir = newdir
End If
End Function
Private Sub Archive_Click()
Dim today As String
today = Format(Now, "dd mmmm yyyy")
MakeFolder (today)
Call CopyA
End Sub
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 SizeChecking()
Dim olddir() As String, newdir() As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim n As Integer, a As String
EnumDir olddir(), "C:\TestOrator\Outgone\*.txt"
EnumDir newdir(), MyNewDir
Debug.Print "files:" & UBound(olddir) & "," & UBound(newdir)
For n = 0 To UBound(olddir)
Debug.Print olddir(n) & " , " & newdir(n)
Debug.Print FileLen(olddir(n)) & " , " & FileLen(newdir(n))
If FileLen("C:\TestOrator\Outgone\" & olddir(n)) = FileLen(MyNewDir & newdir(n)) Then
'files are the same size
MsgBox "files are the same size"
FSO.DeleteFile "C:\TestOrator\Outgone\*.txt"
Else
'files are not the same size
MsgBox "The Files that were transferred were not the same size."
End If
Next n
End Sub
Public Sub CopyA()
Dim today As String
Dim FSO As Object
On Error GoTo NOFSO
Set FSO = CreateObject("Scripting.FileSystemObject")
today = Format(Now, "dd mmmm yyyy")
On Error Resume Next
FSO.CopyFile "C:\TestOrator\Outgone\*.txt", MyNewDir, True
Call SizeChecking
'instead of just deleting the files here I want to check that the contents
'of the copied file is the same size as the contents of the original files
FSO.CopyFile "C:\TestOrator\Outgone\*.doc", MyNewDir, True
FSO.DeleteFile "C:\TestOrator\Outgone\*.doc"
FSO.CopyFile "C:\TestOrator\Outgone\*.exe", MyNewDir, True
FSO.DeleteFile "C:\TestOrator\Outgone\*.exe"
MsgBox "The files have been Successfully transferred"
Set FSO = Nothing
Exit Sub
NOFSO:
MsgBox "FSO CreateObject Failed, Copying of files"
End Sub
-
Sep 15th, 2000, 11:39 AM
#11
Hyperactive Member
Just thought I would chime in. The problem seems to be that the FSO object doesn't know what file to delete. In the SizeChecking function, changed the FSO.DeleteFile to this:
Code:
Sub SizeChecking()
Dim olddir() As String, newdir() As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim n As Integer, a As String
EnumDir olddir(), "C:\TestOrator\Outgone\*.txt"
EnumDir newdir(), MyNewDir
Debug.Print "files:" & UBound(olddir) & "," & UBound(newdir)
For n = 0 To UBound(olddir)
Debug.Print olddir(n) & " , " & newdir(n)
Debug.Print FileLen(olddir(n)) & " , " & FileLen(newdir(n))
If FileLen("C:\TestOrator\Outgone\" & olddir(n)) = FileLen(MyNewDir & newdir(n)) Then
'files are the same size
MsgBox "files are the same size"
FSO.DeleteFile "C:\TestOrator\Outgone\" & olddir(n)
Else
'files are not the same size
MsgBox "The Files that were transferred were not the same size."
End If
Next n
End Sub
Hope this helps.
-
Sep 15th, 2000, 12:05 PM
#12
transcendental analytic
Or maybe you just could leave the FSO out and have one less reference in your project 
Code:
Sub SizeChecking()
Dim olddir() As String, newdir() As String
Dim n As Integer, a As String
EnumDir olddir(), "C:\TestOrator\Outgone\*.txt"
EnumDir newdir(), MyNewDir
For n = 0 To UBound(olddir)
If FileLen("C:\TestOrator\Outgone\" & olddir(n)) = FileLen(MyNewDir & newdir(n)) Then
'files are the same size
MsgBox "files are the same size"
Kill "C:\TestOrator\Outgone\" & olddir(n)
Else
'files are not the same size
MsgBox "The Files that were transferred were not 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.
-
Sep 15th, 2000, 03:50 PM
#13
Even if it's actually has been stated before in this thread I would like to ******** it.
The Dir statement only returns the file name and not the path.
Consider the following statement:
Code:
Dim sFileName As String
sFileName = Dir("C:\OneDirectory\AnAnotherOne\TheFile.txt")
If the above file exist sFileName would be TheFile.txt and NOT C:\OneDirectory\AnAnotherOne\TheFile.txt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|