renaming files

BlitzPlus Forums/BlitzPlus Programming/renaming files

julianbury(Posted 2006) [#1]
Hi Brains ;-)

How can I get BlitzPlus to rename files?
There are batches of files that I have been backing up for years, all named for their creation date and subject.
I now wish to change the date format which means renaming files.
But I cannot, for some reason, find the command in B+ that does this.
Would somebody be kind enough to point me to it?

Thank you for your time and trouble :-)

Julian ((.)(.))

OoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO


Grey Alien(Posted 2006) [#2]
hmm, yes there isn't a command in BlitzPlus to do that. You might have to call an appropriate windows API function instead ... as to which one .. sorry :-( hmm just check my Delphi Win32 help and coulndn't find anything, weird!


Andres(Posted 2006) [#3]
Function RenameFile%(path$, newpath$)
	CopyFile path$, newpath$
	If FileType(newpath$) > 0 Then
		DeleteFile path$
		Return True
	EndIf
End Function



Grey Alien(Posted 2006) [#4]
Nice function. I realised that was an option but was trying to avoid it as it seemed inefficient when there must be a simpler way ...


julianbury(Posted 2006) [#5]
Thank you Andres for the function :-)

I wasted all that time looking for a command :-/

Still ...

Function RenameFile%(path$, newpath$)
CopyFile path$, newpath$
If FileType(newpath$) > 0 Then
DeleteFile path$
Return True
EndIf
End Function

... Problem solved (^_^)

Julian (0_=)

qpqpqpqpqpqpqpqpqpqpqpqpqp


*(Posted 2006) [#6]
The only downside of this is if its a big file the user will need the space to 'rename' the file. I would go with the WinAPI call myself you could always call it using execfile:

ExecFile "Rename "+path$+" "+newpath$


should do it.


Andres(Posted 2006) [#7]
Shouldn't there be quotes around the paths? Many files and folders contain spaces. Or it must be converted to ******~1 ?


Grey Alien(Posted 2006) [#8]
well it's easy enough to put quotes round the paths, best to write a function to do it for reuse :-) That's neat Execfile as it runs a dos command haha, but it'll work much quicker than copying.


Andres(Posted 2006) [#9]
Wouldn't CreateProcess be better for it?