Jump to content


Photo

Rename file extension


  • Please log in to reply
2 replies to this topic

#1 mobid

mobid

    GMC Member

  • New Member
  • 3 posts

Posted 01 August 2010 - 10:01 PM

So i simply want to rename a batch of files but the code returns no errors and doesn't do anything

q=get_directory_alt("","")


fname = file_find_first(q + "\*.txt",fa_hidden);
while (fname != '')
{
filename_change_ext(fname,"xml")
fname = file_find_next();
}
file_find_close();

Am I using it wrong or something?
  • 0

#2 brianp

brianp

    Brian Prestley

  • GMC Member
  • 111 posts
  • Version:Unknown

Posted 26 August 2010 - 06:07 PM

Instead of actually renaming the files, you are just changing the strings in GM. From the Manual

The following functions can be used to change file names. Note that these functions do not work on the actual files they only deal with the strings.


Instead, try file_rename(oldname,newname)
(something like that)


Edited by brianp, 26 August 2010 - 06:08 PM.

  • 0

#3 ragarnak

ragarnak

    GMC Member

  • Retired Staff
  • 19468 posts
  • Version:GM8

Posted 26 August 2010 - 06:46 PM

So i simply want to rename a batch of files but the code returns no errors and doesn't do anything <snip code>

Its a bit like 'brianp' says, but you're not even actually changing strings ...

The "filename_change_ext(fname,"xml")" in your code returns a new string with the extension changed from ".txt" to ".xml". After that you have to use that string as the "newname" argument in the "file_rename(...)" command 'brianp' allready mentioned. The "oldname" argument is what you now have in the "fname" variable.
Oh yeah, you need to use dotxml (".xml"), not just "xml".

Like this :
PRE
--------------------
q=get_directory_alt("","")
fname = file_find_first(q + "\*.txt",fa_hidden);
while (fname != '')
{
NewName = filename_change_ext( fname, ".xml")
file_rename(fname,NewName)
fname = file_find_next();
}
file_find_close();
--------------------

Hope that helps.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users