Page 1 of 1

RenameDirectory()

Posted: Wed Feb 04, 2015 6:38 am
by PB Fanatic
I can't believe this command doesn't exist after all these years! :shock:

And how do we do it in the meantime? A search for "rename directory" comes up with 0 relevant results. :?

Re: RenameDirectory()

Posted: Wed Feb 04, 2015 7:07 am
by Marc56us
PB Fanatic wrote:And how do we do it in the meantime? A search for "rename directory" comes up with 0 relevant results. :?
Hello,

Use the keyword folder, instead of directory for search :wink:

http://www.purebasic.com/documentation/ ... efile.html

[...]This function can also be used to rename/move directories.[...]

Re: RenameDirectory()

Posted: Wed Feb 04, 2015 7:58 am
by PB Fanatic
Marc56us wrote:Use the keyword folder, instead of directory
What the? We have CreateDirectory, CopyDirectory, DeleteDirectory... but not RenameDirectory. :shock: So searching for "directory" is therefore a totally logical thing to do, as opposed to searching for "folder". :mrgreen: Thanks for pointing it out, though.

Re: RenameDirectory()

Posted: Wed Feb 04, 2015 6:57 pm
by Little John
PB Fanatic wrote:What the? We have CreateDirectory, CopyDirectory, DeleteDirectory... but not RenameDirectory. :shock: So searching for "directory" is therefore a totally logical thing to do
I agree.
So open the English help file, click at the "Search" tab, and then enter
rename directory
As result, the topic titled RenameFile() will be listed, which contains the following sentence:
This function can also be used to rename/move directories.
VoilĂ ! :)

Re: RenameDirectory()

Posted: Thu Feb 05, 2015 11:20 am
by PB Fanatic
It would be better just to have a new command called RenameDirectory() that works.

Re: RenameDirectory()

Posted: Thu Feb 05, 2015 11:26 am
by Bisonte
make it by your own :

Code: Select all

Procedure RenameDirectory(OldName.s, NewName.s)
  ProcedureReturn RenameFile(OldName, NewName)
EndProcedure
or with a macro....

Re: RenameDirectory()

Posted: Thu Feb 05, 2015 1:21 pm
by PB Fanatic
A procedure or macro that wraps RenameFile() simply doesn't work:

Code: Select all

Macro RenameDirectory(old,new)
  RenameFile(old,new)
EndMacro

old$=GetTemporaryDirectory()+"old"

Debug CreateDirectory(old$)       ; 1 - Okay
Debug RenameDirectory(old$,"new") ; 0 - Fails

Re: RenameDirectory()

Posted: Thu Feb 05, 2015 2:04 pm
by Shardik
PB Fanatic wrote:A procedure or macro that wraps RenameFile() simply doesn't work
It works quite fine when doing it right... :wink:

You have to specify the complete path to your renamed directory. On my old Windows XP SP3 even your example works fine but probably not as expected by you: it renamed the directory "old" and moved it to C:\new. If you are not allowed to write to the C:\ root directory you will obtain a return code of 0.

Code: Select all

Macro RenameDirectory(old,new)
  RenameFile(old,new)
EndMacro

old$=GetTemporaryDirectory()+"old"

Debug CreateDirectory(old$)       ; 1 - Okay
Debug RenameDirectory(old$,GetTemporaryDirectory()+"new") ; 1 - Okay

Re: RenameDirectory()

Posted: Thu Feb 05, 2015 3:08 pm
by PB Fanatic
Oops! :oops:

Re: RenameDirectory()

Posted: Thu Feb 05, 2015 4:18 pm
by Little John
PB Fanatic wrote:A procedure or macro that wraps RenameFile() simply doesn't work:
Small addition to Shardik's post:
You have always to use proper names, regardless whether you use RenameFile() directly, or whether you wrap it in a macro.
So any problem with a path or file/directory name that you encounter in this context, has nothing got to do with the macro itself.