November 24, 2020, 06:44:49 AM

Author Topic: [bb] Rename File Deluxe by -=Darkheart=- [ 1+ years ago ]  (Read 594 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Rename File Deluxe by -=Darkheart=- [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
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
  1. Function Renamefile(orgfile$,newfile$)
  2. If FileType (orgfile$)<>1 Then RuntimeError "File " + orgfile$ + " Does Not Exist!"
  3. thispath$=bbgetDir$(orgfile$)
  4. thisfile$=bbgetfile$(newfile$)
  5. mynewfile$=thispath$+thisfile$
  6. If orgfile$=mynewfile$ Then RuntimeError "New Filename Cannot Match Old Filename!"
  7. CopyFile orgfile$,mynewfile$
  8. DeleteFile orgfile$
  9. End Function
  10.  
  11. Function bbGetDir$(path$)
  12.         For a = Len(path$) To 1 Step -1
  13.                 byte$ = Mid(path$,a,1)
  14.                 If byte$ = ""
  15.                         Return Left(path$,a)
  16.                 EndIf
  17.         Next
  18.         Return ""
  19. End Function
  20.  
  21.  
  22. Function bbGetFile$(path$)
  23.         For a = Len(path$) To 1 Step -1
  24.                 byte$ = Mid(path$,a,1)
  25.                 If byte$ = ""
  26.                         Return Right(path$,Len(path$)-a)
  27.                 EndIf
  28.         Next
  29.         Return path$
  30. End Function
  31.  
  32. ;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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal