|
-
Dec 9th, 2009, 07:36 PM
#1
Thread Starter
Member
[RESOLVED] renaming file on upload.
How would I go about making sure when a file is uploaded that it just won't keep over writting itself?
This is the code on upload
Code:
Inet1.Execute , "PUT ""c:\Windows\errors.txt""" & "errors.txt"
Let's say I want it to upload as the following:
errors
errors1
errors2
Pretty much just keep increasing the number the txt file won't keep overwritting itself.
-
Dec 10th, 2009, 02:01 AM
#2
Re: renaming file on upload.
One solution is to include a date: Inet1.Execute , "PUT ""c:\Windows\errors.txt"" errors_" & Format$(Now, "YYYY-MM-DD") & ".txt"
This will overwrite, but only a file uploaded the same day.
-
Dec 10th, 2009, 02:21 AM
#3
Re: renaming file on upload.
You could use this:
from vbwire 11-19-08 if the filname exists it appends a number to the filename
Code:
Public Function GetUniqueFileName(ByVal FileName As String) As String
Dim uniqueID As Long
Dim sFile As String
Dim sExt As Long, iExt As Integer
sFile = Dir$(FileName, vbArchive)
If sFile = vbNullString Then
GetUniqueFileName = FileName
Else
iExt = InStrRev(FileName, ".")
If iExt = 0 Then
FileName = FileName & "[#]"
Else
FileName = Left$(FileName, iExt - 1) & "[#]" & Mid$(FileName, iExt)
End If
Do
uniqueID = uniqueID + 1
sFile = Dir$(Replace$(FileName, "#", uniqueID), vbArchive)
Loop Until sFile = vbNullString
GetUniqueFileName = Replace$(FileName, "#", uniqueID)
End If
End Function
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Dec 10th, 2009, 10:06 AM
#4
Thread Starter
Member
Re: renaming file on upload.
 Originally Posted by isnoend07
You could use this:
from vbwire 11-19-08 if the filname exists it appends a number to the filename
Code:
Public Function GetUniqueFileName(ByVal FileName As String) As String
Dim uniqueID As Long
Dim sFile As String
Dim sExt As Long, iExt As Integer
sFile = Dir$(FileName, vbArchive)
If sFile = vbNullString Then
GetUniqueFileName = FileName
Else
iExt = InStrRev(FileName, ".")
If iExt = 0 Then
FileName = FileName & "[#]"
Else
FileName = Left$(FileName, iExt - 1) & "[#]" & Mid$(FileName, iExt)
End If
Do
uniqueID = uniqueID + 1
sFile = Dir$(Replace$(FileName, "#", uniqueID), vbArchive)
Loop Until sFile = vbNullString
GetUniqueFileName = Replace$(FileName, "#", uniqueID)
End If
End Function
This code just blew up my brain.
I'm guessing that I'd put this... in the general part and it'll take care of the rest?
-
Dec 10th, 2009, 12:55 PM
#5
Re: renaming file on upload.
 Originally Posted by Endorphine
This code just blew up my brain.
I'm guessing that I'd put this... in the general part and it'll take care of the rest?
Dim sFileName as string
sFileName = "c:\Windows\errors.txt"
sFileName = GetUniqueFileName(sFileName)
Then
Inet1.Execute , PUT sFileName
Not sure about the quotes("")
FileName will look like this:
"c:\Windows\errors.txt"
"c:\Windows\errors[1].txt"
"c:\Windows\errors[2].txt"
etc
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
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
|