RenameDirectory()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

RenameDirectory()

Post 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. :?
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: RenameDirectory()

Post 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.[...]
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: RenameDirectory()

Post 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.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: RenameDirectory()

Post 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à! :)
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: RenameDirectory()

Post by PB Fanatic »

It would be better just to have a new command called RenameDirectory() that works.
Last edited by PB Fanatic on Thu Feb 05, 2015 1:23 pm, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: RenameDirectory()

Post 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....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: RenameDirectory()

Post 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
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: RenameDirectory()

Post 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
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: RenameDirectory()

Post by PB Fanatic »

Oops! :oops:
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: RenameDirectory()

Post 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.
Post Reply