Code archives/File Utilities/FileName, FileExtention, FilePath, AddFileExtention
This code has been declared by its author to be Public Domain code.
Download source code
| Does what the name says. I know, there are already two entries, wich do the same, but they will fail, if you want to analyze difficult filnames (ex. "C:\MyDreams...\Testfile" or the example given in the code). I think, you don't know, what the user will type in ... - - - - - - - - - - - - - - - Der Name ist programm. Ich weiß, dass bereits zwei Einträge existieren, diedas selbe machen, aber sie scheitern bei der Analyse schwiediger Dateinamen (z.B. "C:\MyDreams...\Testfile" oder dem Beispiel, das im Programmcode gegeben wird). Ich bin der Meinung, du weißt nicht, was der Benutzer eingeben wird ... |
; Example | Beispiel File$ = "C:\My.Files\Docs/File.txt" ; Difficult Filename | Schwieriger Dateiname Print FileName$(File$) Print FileExtention$(File$) Print FilePath$(File$) WaitKey End Function FileName$(File$) For I% = Len(File$) To 1 Step -1 If Mid(File$, I%, 1) = "\" Or Mid(File$, I%, 1) = "/" Then Return Mid(File$, I% + 1) Next Return File$ End Function Function FileExtention$(File$) For I% = Len(File$) To 1 Step -1 If Mid(File$, I%, 1) = "." Return Mid(File$, I% + 1) If Mid(File$, I%, 1) = "\" Or Mid(File$, I%, 1) = "/" Then Return "" Next End Function Function FilePath$(File$) For I% = Len(File$) To 1 Step -1 If Mid(File$, I%, 1) = "\" Or Mid(File$, I%, 1) = "/" Then Return Left(File$, I% - 1) Next End Function ; Adds a file extention, if not exists. | Fügt eine Dateiendung hinzu falls noch keine da ist. Function AddFileExtention$(File$, Extention$) If FileExtention(File$) = "" Then Return File$ + "." + Extention$ Else Return File$ End Function |