|
-
Dec 19th, 2007, 02:29 PM
#1
Thread Starter
Lively Member
How do I NOT overwrite files I am creating that have the same filename?
This program is pretty huge, so I wont go into too much detail, but basically the program takes a file, renames it based on a naming convention I have created, and sorts it into the appropriate folder. If the folder doesn't exist, it will be created, etc. Then the files are added to a database where I can search for them and pull them up.
Everything works great, except one thing - sometimes files need to have the same name, and when this happens, it will overwrite the old one and add the entry to the database. So I have to entries in the db (which is fine) but only one file. So if I try to open the first file from my db, the new one opens and the old one doesnt exist because it has been overwritten. Does this make sense?
What I want to be able to do is check if a file exists and if it does, just add a (1) or (2) to the end of it. How would I do this?
Code:
FindFileName 'naming convention that creates the filename
Dim x As String
Dim y As String
x = Trim$(strImportPath)
strFileExt = Right$(x, Len(x) - InStr(x, ".") + 1)
y = strName & strFileExt
lblName.Caption = y
If detailError = False Then
'''Move File
MakeSureDirectoryPathExists strNameFolder
FileCopy x, y
Kill strImportPath
'''Save to Documents Database
SaveToDB
Public Sub SaveToDB()
Set Rs = New ADODB.Recordset
Rs.Open "tbl_documents", Cn, adOpenKeyset, adLockPessimistic, adCmdTable
With Rs
.AddNew
.Fields("Location") = strName & strFileExt
.Fields("FileType") = strFileExt
.Fields("Name") = cboName.Text
.Update
End With
Rs.Close
Set Rs = Nothing
End Sub
Here is my code for making the folder, copying the file and renaming it:
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
|