March 01, 2021, 10:47:44 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
File Utilities
»
[bb] RenameFile by _PJ_ [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] RenameFile by _PJ_ [ 1+ years ago ] (Read 571 times)
BlitzBot
Jr. Member
Posts: 1
[bb] RenameFile by _PJ_ [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
RenameFile
Author :
_PJ_
Posted :
1+ years ago
Description :
Very simply, this is a means to Rename file/folders from within Blitz.
These functions hijack the 'pseudo-DOS' implemented in Windows XP. They should work with NT, Windows 2000 and earlier Windows versions, but I have no idea if the DOS command interface is included anymore with the likes of Vista and Windows 7
Also, since the fake DOS environment is based on virtual 16-bit architecture, I am not sure what, if any, effects there are in Windows 64-bit versions.
Best advice is see if Start-Run-cmd brings up a command prompt interface or not.
I added the ability to do some bulk renaming if required, this is purely optional, but requires tracking a value which is passed in to the function. This value should be incremented each call.
To ensure against possible errors and bad calls, I added some simple (a bit sloppy to be honest) checks for the file extension and such.
I sincerely suggest that this function is tested on some unimportant files/directories before putting it to real use. JUST IN CASE!
___________________
To use all the features, call the RenameFile(path$, NewFile$,Count_Renamed) function, parameters are:
Path: Complete path and filename to the file to be renamed
NewFile: The new name for the file (If you omit the extension, the same extension as the original will be added)
Count_Renamed: If required, This is the tracking variable for consecutive batch processing.
Otherwise, for more simplistic, direct conversions, you can directly call
ExecuteRename(Path$, NewFile$)
This function is the main renaming and imply changes the name of the file / folder that path$ points to, to NewFile$. If NewFile$ already exists, then nothing happens.
__________________________
Lastly:
A return value is added which corresponds to the filetype of the newly renamed file. This is just an extra.
It may be that this fails due to the time taken for the computer to actually rename the file.
Code :
Code: BlitzBasic
Function
RenameFile
(
Path$=
""
,NewFile$=
""
,Count_Renamed=
False
)
;Count_Renamed should be incremented each call for batch processing
Local
Consecutor$=
""
If
(
Count_Renamed
)
Then
Consecutor$=
Str
(
Count_Renamed
)
If
(
Right
(
path,
1
)
=
"."
)
Then
Return
If
(
Path$=
""
)
Then
Path$=
CurrentDir
(
)
If
(
Right
$
(
Path,
1
)
=
""
)
Then
path$=
Left
(
path$,
Len
(
path$
)
-
1
)
If
(
NewFile$=
""
)
If
(
FileType
(
Path$
)
=
2
)
NewFile$=
"Renamed Folder"
ExecuteRename
(
Path$,NewFile$+Consecutor$
)
Else
If
(
FileType
(
Path$
)
=
1
)
NewFile$=
"Renamed File"
Else
Return
End If
End If
End If
Local
Extension_separator=
Instr
(
Path$,
"."
)
Local
Extension$=
""
Local
Path_Separators
Local
LastPath=
0
While
(
Path_separators
)
LastPath=Path_Separators
Path_Separators=
Instr
(
Path$,
""
,Path_Separators+
1
)
Wend
If
(
(
Not
(
Instr
(
NewFile$,
"."
)
)
)
And
(
LastPath<Extension_Separator
)
)
Then
Extension$=
"."
+
Right
(
Path,
(
Len
(
Path
)
-Extension_Separator
)
)
Return
ExecuteRename
(
Path$,NewFile$+Consecutor$+Extension$
)
End Function
Function
ExecuteRename%
(
Path$,NewFile$
)
ExecFile
(
Chr
(
34
)
+
"cmd"
+
Chr
(
34
)
+
" /c RENAME "
+
Chr
(
34
)
+Path$+
Chr
(
34
)
+
" "
+
Chr
(
34
)
+NewFile$+
Chr
(
34
)
)
Local
Path_Separators
Local
LastPath=
0
While
(
Path_separators
)
LastPath=Path_Separators
Path_Separators=
Instr
(
Path$,
""
,Path_Separators+
1
)
Wend
Local
Parent$=
Left
$
(
Path,LastPath
)
+NewFile$
Return
(
FileType
(
Parent$
)
)
End Function
Comments :
Streaksy(Posted 1+ years ago)
Tried it in Vista... didnt seem to work ;/
_PJ_(Posted 1+ years ago)
Thanks for the feedback Streaksy, I assume that the Start - Run - "cmd" doesn't invoke a command prompt interface?
Streaksy(Posted 1+ years ago)
Vista has cmd... I don't have it in my start menu (forgot how) but I can invoke it with New Task from in task manager. I use it for IPCONFIG like everyone else ;P
_PJ_(Posted 1+ years ago)
Okay, I made a small change, but it shouldn't have been anything critical, the function
should
work provided Blitz can run the cmd.Perhaps there's a permissions issue?Could/did you try different paths, just in case?
Streaksy(Posted 1+ years ago)
Doesn't seem to work but I'm cursed with Vista and always get weird problems. I could by a brand new pc with a fresh vista and still get mad problems nobody's ever heard of.Guess you need another Vista user to test it ;/
_PJ_(Posted 1+ years ago)
No wworries, Thanks for the info anyway, if I can find a solution for you, I'll be sure to post about it
Streaksy(Posted 1+ years ago)
No bother
Nate the Great(Posted 1+ years ago)
works like a charm on vista here
_PJ_(Posted 1+ years ago)
Noticed a small error in the code.(Fixed above now)Last_Path was also written as LastPath in some cases. Might have been an issue in some cases.
_PJ_(Posted 1+ years ago)
Does the new Powershell thingy that Miscrosoft released with Windows Update have any significance here?From what I see, it seems to be some kinda replkacement for the cmd shell?I'm on XP so presumably it's oinly included to help compaitibilities with Win7 etc???
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
File Utilities
»
[bb] RenameFile by _PJ_ [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal