Author Topic: inline call to rename()  (Read 8023 times)

9940

  • Guest
inline call to rename()
« on: 2009-Jul-28 »
I wish to call rename() because glbasic don't have anything to rename or move files/dirs.
But I get an error. Someone know how can I implement it correctly ?

Code: (glbasic) [Select]
INLINE
     }
     extern int rename(const char *_old, const char *_new);
     namespace __GLBASIC__
     {
ENDINLINE

FUNCTION inline_Rename: old$, new$
     INLINE
          rename(old_Str.c_str(), new_Str.c_str());
     ENDINLINE
ENDFUNCTION

gpc_temp1.o:gpc_temp1.cpp:(.text+0x248): undefined reference to `rename(char const*, char const*)'


MrTAToad

  • Guest
Re: inline call to rename()
« Reply #1 on: 2009-Jul-28 »
Try :

Code: (glbasic) [Select]
INLINE
     }
     extern "C" int rename(const char *_old, const char *_new);
     namespace __GLBASIC__
     {
ENDINLINE

FUNCTION inline_Rename: old$, new$
     INLINE
          rename(old_Str.c_str(), new_Str.c_str());
     ENDINLINE
ENDFUNCTION

And see if it works.   Which is does...

9940

  • Guest
Re: inline call to rename()
« Reply #2 on: 2009-Jul-28 »
Thx  :good:

                                                                                                                 
However I don't think it is hard to make a command like RENAME() integrated in glbasic.

MrTAToad

  • Guest
Re: inline call to rename()
« Reply #3 on: 2009-Jul-28 »
You can actually do it with COPYFILE and KILLFILE...

9940

  • Guest
Re: inline call to rename()
« Reply #4 on: 2009-Jul-28 »
Quote

Quote
function copy: a$, b$
copyfile a$, b$
killfile a$
endfunction

Yes, it works.. but if you have a huge file/dir it may take long time   
and may not be enough space


MrTAToad

  • Guest
Re: inline call to rename()
« Reply #5 on: 2009-Jul-28 »
Even if Gernot included it, a large file could take a long time anyway.

What you need to do is put a copying system in a seperate thread or something like that :)

9940

  • Guest
Re: inline call to rename()
« Reply #6 on: 2009-Jul-28 »
Quote
Even if Gernot included it, a large file could take a long time anyway.

No, beacause rename can move a file without copy it. Ex: RENAME("file1.dat", "..\\file1.dat")

MrTAToad

  • Guest
Re: inline call to rename()
« Reply #7 on: 2009-Jul-28 »
Quite true there.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10814
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: inline call to rename()
« Reply #8 on: 2009-Jul-29 »
V7 has MOVEFILE.

9940

  • Guest
Re: inline call to rename()
« Reply #9 on: 2009-Jul-29 »
If you are using the C func rename() directly, MOVEFILE could be an incorrect name because it can move directory too.

Is DOESDIREXIST() implemented in v7 ?
« Last Edit: 2013-Jun-10 by 9940 »

Hatonastick

  • Guest
Re: inline call to rename()
« Reply #10 on: 2009-Jul-29 »
Hey Gernot, I can't see that one in the v7 help file?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10814
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: inline call to rename()
« Reply #11 on: 2009-Jul-29 »
oops - on my todo. I'll add that. And add that DOESFILEEXIST checks for the existence of a directory.

Hatonastick

  • Guest
Re: inline call to rename()
« Reply #12 on: 2009-Jul-29 »
Fantastic stuff! :)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1600
    • View Profile
    • AMpostata Website
Re: inline call to rename()
« Reply #13 on: 2012-Mar-16 »
Is there a way I can RENAME a FOLDER in all (mobile) devices?
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

MrTAToad

  • Guest
Re: inline call to rename()
« Reply #14 on: 2012-Mar-16 »
You should be able to call the C rename function, although you may need to change permissions for some devices...