dcsimg
Results 1 to 6 of 6

Thread: Run Time Error 58(I think I know the resolution just not the code - with screenshots)

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Run Time Error 58(I think I know the resolution just not the code - with screenshots)

    Name:  30xfu35.png
Views: 595
Size:  38.2 KB

    My educated guess is that I simply need a string telling VB "if the file already exists, name it as filename (1) .. (2)... etc.." but I don't know if that is the resolution nor if that is the problem.

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,910

    Re: Run Time Error 58(I think I know the resolution just not the code - with screensh

    Code:
        If Dir$(strDest)<>"" Then
            Msgbox "File Already Exists
        Else
            'Do your rename
        End If

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Re: Run Time Error 58(I think I know the resolution just not the code - with screensh

    Thank you. Will I need to replace "'do your rename" with an actual script for the renaming or will this do it for me as well?

    Thanks

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Run Time Error 58(I think I know the resolution just not the code - with screensh

    Here is a couple ways

    If Dir$(strDest)<>"" Then
    Msgbox "File Already Exists
    Else
    Dim i As Integer

    For i = 0 To 100
    If Dir$(Left(strDest,Len(strDest) - 4) & i & Right(strDest,4)) = "" Then
    ' name file Left(strDest,Len(strDest) - 4) & i & Right(strDest,4)
    End If
    Next
    End If

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,132

    Re: Run Time Error 58(I think I know the resolution just not the code - with screensh

    I think updating the rename procedure to this would work at incrementing the file names.
    Code:
    Private Sub cmdRename_Click()
    Dim i As Integer
    Dim x As Integer
    Dim strSource As String
    Dim strDest As String
    Dim strExt As String
    Dim strFileName As String
    
        If Right(strSourcePath, 1) <> "\" Then
            strSourcePath = strSourcePath & "\"
        End If
        
        For i = 0 To lstFiles.ListCount - 1
            strSource = strSourcePath & lstFiles.List(i)
            
            strDest = lstFiles.List(i)
            
            For x = 0 To txtFind.Count - 1
                strDest = Replace(strDest, txtFind(x).Text, txtReplace(x).Text)
            Next x
            
            ' get the file extension
            strExt = Mid(strDest, InStrRev(strDest, "."))
            ' strip the extention off the file name
            strDest = Replace(strDest, strExt, "")
            
            
            strFileName = strDest
            x = 0
            
            ' loop until you have an unused name
            Do While Dir(strSourcePath & strDest & strExt) <> ""
                x = x + 1
                strDest = strFileName & "(" & x & ")"
            Loop
            
            strDest = strSourcePath & strDest & strExt
            
            Name strSource As strDest
    
        Next i
        
        LoadFiles strSourcePath
    End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Re: Run Time Error 58(I think I know the resolution just not the code - with screensh

    Thank you both, I'll check them out.

    I've been trying to Google it but just don't know what to do Google, how do I get it so it's like "If filename already exists then add (1).. (2).. etc. as a suffix"? Or is that what you've given me?

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width