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?
Rename file extension
Started by mobid, Aug 01 2010 10:01 PM
2 replies to this topic
#1
Posted 01 August 2010 - 10:01 PM
#2
Posted 26 August 2010 - 06:07 PM
Instead of actually renaming the files, you are just changing the strings in GM. From the Manual
Instead, try file_rename(oldname,newname)
(something like that)
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.
#3
Posted 26 August 2010 - 06:46 PM
Its a bit like 'brianp' says, but you're not even actually changing strings ...So i simply want to rename a batch of files but the code returns no errors and doesn't do anything <snip code>
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 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











