Results 1 to 5 of 5

Thread: [RESOLVED] renaming file on upload.

  1. #1

    Thread Starter
    Member Endorphine's Avatar
    Join Date
    Dec 2009
    Location
    Shelby, Ohio
    Posts
    51

    Resolved [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.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  3. #3
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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

  4. #4

    Thread Starter
    Member Endorphine's Avatar
    Join Date
    Dec 2009
    Location
    Shelby, Ohio
    Posts
    51

    Re: renaming file on upload.

    Quote Originally Posted by isnoend07 View Post
    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?

  5. #5
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: renaming file on upload.

    Quote Originally Posted by Endorphine View Post
    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
  •  



Click Here to Expand Forum to Full Width