[bb] Rename File Deluxe by -=Darkheart=- [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : Rename File Deluxe
Author : -=Darkheart=-
Posted : 1+ years ago

Description : Does what is says on the tin, you don't have to include a path for the renamed file it will use the path of the original file.

Code :
Code (blitzbasic) Select
Function Renamefile(orgfile$,newfile$)
If FileType (orgfile$)<>1 Then RuntimeError "File " + orgfile$ + " Does Not Exist!"
thispath$=bbgetDir$(orgfile$)
thisfile$=bbgetfile$(newfile$)
mynewfile$=thispath$+thisfile$
If orgfile$=mynewfile$ Then RuntimeError "New Filename Cannot Match Old Filename!"
CopyFile orgfile$,mynewfile$
DeleteFile orgfile$
End Function

Function bbGetDir$(path$)
For a = Len(path$) To 1 Step -1
byte$ = Mid(path$,a,1)
If byte$ = ""
Return Left(path$,a)
EndIf
Next
Return ""
End Function


Function bbGetFile$(path$)
For a = Len(path$) To 1 Step -1
byte$ = Mid(path$,a,1)
If byte$ = ""
Return Right(path$,Len(path$)-a)
EndIf
Next
Return path$
End Function

;Example Renamefile ("c:um.bb","scum.bb")


Comments :


XtremeCoder(Posted 1+ years ago)

 You could just copy the file to the same folder with a different name and then delete the older one, lot less code involved.