Easy way to rename file in blitz?

Blitz3D Forums/Blitz3D Programming/Easy way to rename file in blitz?

Ross C(Posted 2010) [#1]
Hey, i'm looking for an easy way to rename a file, without having to open it and save it back to the harddisc, and delete the old one. I have alot of files, and i reckon doing this with so many files will not only put my hard disc under unnessesary strain, but also fragment it more.

Any suggestions?


_PJ_(Posted 2010) [#2]
Aside from possible AP{I stuff, which I am not sure even how to go about that), the simplest way I know in blitz is to use CopyFile and DeleteFile

Since you are manipulating whole files at a time, and replacing them in the same places relatively, then defragmentation is apparwently minimal.

Unless this is something specifivc to a blitz app you're working on, therer's a VERY handy tool which integrates into your Windows Shell context menu called "FileMenuTools" by Lopesoft

http://www.lopesoft.com

It's Free and has some invaluable features, including a BULK RENAME function!


Ross C(Posted 2010) [#3]
Surely fragmentation would occur though, as i'm opening a file, which i wouldn't delete till the new file was saved (in case of computer shutdown, and i possibly lose a file.

Anyway, thanks for the suggestion. I found another awesome tool, File Renamer Basic, on download.com.

Gives you the ability to bulk rename files, add numbers, change the case of the extension etc etc

Just seems a bit of an oversight, not having a rename file option in blitz though.


_PJ_(Posted 2010) [#4]
Yeah, soething that would have been very handy. Glad you found a solution though :)


Hardcoal(Posted 2011) [#5]
so hard to add this option a release new blitz3d version?


Yasha(Posted 2011) [#6]
...well, since someone already dredged up this old topic -

CopyFile oldname, newname
DeleteFile oldname


EDIT: Stupid me, of course this doesn't actually address the problem that rewriting data to the disk is unnecessarily wasteful. Sorry. Rroff's solution is sensible though.

Last edited 2011


Rroff(Posted 2011) [#7]
Anyone would have thought it would be difficult to google "Windows API rename file" and create a decl for the function MoveFileEx from Kernel32.dll and implement it in your code...


Yue(Posted 2011) [#8]
-.-


Hardcoal(Posted 2011) [#9]
lol if i knew how to do i would
but im newbe in this field of dlls.
purheps if someone guide me i would


Warner(Posted 2011) [#10]
Save the following file to the folder "c:\program files\blitz3d\userlibs\"
and name it "kernel32.decls"
.lib "kernel32.dll"

api_MoveFile% (lpExistingFileName$, lpNewFileName$) : "MoveFileA"

Then, save the following program in a folder where there is also a file called "one.txt".
api_MoveFile("one.txt", "two.txt")
WaitKey

When you run this program, it will rename "one.txt" to "two.txt".


Hardcoal(Posted 2011) [#11]
tnx ill try


Hardcoal(Posted 2011) [#12]
wow this is cool it works i just changeg the comman to renamefile_api

i would like to know what is the priniciple of dll making
then i will make more.

cheers


Warner(Posted 2011) [#13]
If you want to create your own dll's, look under the "Specs and Utils" tab above this forum. There is a subcat "User Libs Format" you can look into.
For the default Windows DLLs, you could look into MSDN. It describes most of the possible Windows API calls:
http://msdn.microsoft.com/en-us/library/aa383749(v=vs.85).aspx
For instance MoveFile (found it under alphabetical order->M)
http://msdn.microsoft.com/en-us/library/aa365239(v=vs.85).aspx


Hardcoal(Posted 2011) [#14]
great tnx


Adam Novagen(Posted 2011) [#15]
I am officially saving this thread because those links from Warner are SOLID GODDAMN GOLD to me. 8D