Results 1 to 13 of 13

Thread: FileSize?????

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    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]

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    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

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Sorry kedaman. I've only been at VB for three weeks now. How do I use dir??? Sorry if it's a stupid question

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    Thanks again for taking the time.
    Here's what the immediate window has

    files:19,91
    New Text Document (10).txt , ADDSCCUS.DLL

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

    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.

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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!

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224
    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

  11. #11
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    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.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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
  •  



Click Here to Expand Forum to Full Width