-
Aug 6th, 2012, 07:49 AM
#1
Thread Starter
Member
Run Time Error 58(I think I know the resolution just not the code - with screenshots)
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.
-
Aug 6th, 2012, 07:57 AM
#2
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
-
Aug 6th, 2012, 08:10 AM
#3
Thread Starter
Member
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
-
Aug 6th, 2012, 12:38 PM
#4
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
-
Aug 6th, 2012, 03:07 PM
#5
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
-
Aug 7th, 2012, 02:45 AM
#6
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|