Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Takes the name of a file and checks to see if it a...
Author:
KrazyGamer
E-mail:
Click to e-mail author
Submitted:
5/2/2002
Version:
VB3, VB4, V
Compatibility:
VB3, VB4, VB5, VB6, VB.NET
Category:
File Manipulation
Views:
12767
Takes the name of a file and checks to see if it already exists. If it does, it'll increment an ordinal number in the filename until it encounters an available filename, just like Windows does.
Declarations:
'none
Code:
Function MakeUnique(strFile As String, strPath As String, Optional FullPath As Boolean) As String 10 Dim filename$, a, ch$, p$, b, hasExt As Boolean p$ = "" If Right$(strPath, 1) <> "\" Then strPath = strPath & "\" filename$ = strPath & strFile If Dir(filename$) = "" Then If FullPath Then strFile = strPath & strFile MakeUnique = strFile Exit Function End If For a = Len(strFile) To 1 Step -1 ch$ = Mid$(strFile, a, 1) If ch$ = ")" Then a = Len(strFile) + 1: GoTo 20 If ch$ = "." Then hasExt = True: Exit For Next If a = 0 Then a = Len(strFile) 20 If Mid$(strFile, a - 1, 1) = ")" Then For b = a - 2 To 1 Step -1 If IsNumeric(Mid$(strFile, b, 1)) Then p$ = Mid$(strFile, b, 1) & p$ ElseIf Mid$(strFile, b, 1) = "(" Then strFile = Left$(strFile, b) & Trim$(Str$(Val(p$) + 1)) & Right$(strFile, Len(strFile) - a + 2) GoTo 10 Else GoTo 30 End If Next Else If Not hasExt Then a = Len(strFile) + 1 GoTo 30 End If If FullPath Then strFile = strPath & strFile MakeUnique = strFile Exit Function 30 strFile = Left$(strFile, a - 1) & " (2)" & Right$(strFile, Len(strFile) - a + 1) GoTo 10 End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement