PDA

View Full Version : File Deletion


xXziroXx
05-17-2006, 06:40 PM
How can I delete a file on RC with a script? The only alternative that I could find was:


requestfiledeletion( "filepath/filename" )



But like Skyld said when I asked him; thats a function with the scripted Client RC.


Whatever, but can anyone tell me how its done?

Warcaptain
05-17-2006, 07:52 PM
deletefile("path/to/file")

xXziroXx
05-18-2006, 02:36 PM
Didnt work.

Warcaptain
05-19-2006, 02:19 AM
Has to be serverside.

xXziroXx
05-19-2006, 06:18 PM
Has to be serverside.

Duh.


Heres what I tried (file and location are not the same for *security* reasons or whatever):


function onActionServerside()
{
if (params[0] == "DeleteFile") {
echo( "wee"); //Confirms that it get this far
deletefile( "levels/folder/filename.txt" ); // Yes, im trying to delete a .txt
sendtorc("/refreshfilelist"); // Updating the folder
}
}

Warcaptain
05-20-2006, 09:10 AM
Then something is wrong thats beyond what we can see here.


deletefile(str) - returns boolean č

č Script Functions: NPC-Server (http://wiki.graal.net/index.php/Creation/Dev/Script_Functions:_NPC_Server)

xXziroXx
05-21-2006, 07:38 PM
I sent a message to Stefan, hopefully heŽll look into it and/or tell us whats wrong.

Warcaptain
05-21-2006, 09:43 PM
I have used this before, and I just tested it on my NPC-Server and it works.

Perhaps something was done to my NPC-Server? I doubt it would be just mine though.. so maybe Stefan can help.

xXziroXx
05-21-2006, 09:56 PM
Odd. Maybe something with the folder options? Doubt it though since its able to read info from the text files.

xXziroXx
05-23-2006, 06:50 PM
Ok, lets show a more detailed explanation on what im trying to do then. First, the script!


Note: not the actuall script, but I tried this and the file wont get deleted.


function onActionServerSide()
{
if (params[0] == "deletefile") {
echo( "Deleting file...");
deletefile( "levels/items/Weapons/phantombane.txt");
}
}
//#CLIENTSIDE
function onCreated()
{
triggeraction( 0, 0, "serverside", name, "deletefile");
}



Then, lets /find the file on RC!



/find phantombane.txt

......

items/Weapons/phantombane.txt: downloadable, 45 byte, 2006-05-21 18:44:57



Ok, next step: lets add the NPC to myself and check if it gets deleted!



xXziroXx loaded attributes of player xXziroXx
xXziroXx set attributes of player xXziroXx
Deleting file...



Ah, now the file should be deleted, right? But.. its still in the folders! Lets check with /find..



/find phantombane.txt

......

items/Weapons/phantombane.txt: downloadable, 45 byte, 2006-05-21 18:45:31




So, does anyone have a clue what im doing wrong if anything?

Warcaptain
05-23-2006, 06:57 PM
Only thing I can think of, is that you can't delete files in the levels folder.

I delete files regularly from my manadb/items/*.arc folder and it works fine.

-performs a deletion-

See!

xXziroXx
05-24-2006, 09:29 PM
Ok, so I added myself rights for a new folder!


items/


And from there, I could delete the file I tried to delete.. but the problem is, now I cant use loadlines from the documents there since the folder isnt listed in server options.. and as far as I know, you can only add subfolders to leves/ in the folder options.

So if im wrong, and you can add other folders there, please tell me how to do.. if not, am I screwed when it comes to deleting a file?

ApothiX
05-25-2006, 03:12 PM
The file doesn't have to be in the folder config for you to be able to use loadlines and such. Just specify the entire path to it.

xXziroXx
05-25-2006, 09:24 PM
Ok, I got it to work when I moved the files to a folder thats not a sub-folder to levels/.

Warcaptain
05-25-2006, 09:48 PM
Ok, I got it to work when I moved the files to a folder thats not a sub-folder to levels/.


Yeah, just like I thought. :)

You use deletelevel() to delete things in the levels folder.. at least you can delete levels that way.

xXziroXx
05-25-2006, 10:08 PM
I know. I tried using deletelevel() on other files aswell, didnt work though.

Admins
05-30-2006, 01:27 AM
deletefile() is not allowed to delete files in the levels folder, for security reasons, since there is no system for script rights yet. deletelevel() can be used for deleting level files (.nw, .graal).

Yen
05-30-2006, 10:58 PM
Couldn't we rename another type of file to a .nw or .graal using a script, then delete it?

Skyld
05-30-2006, 11:55 PM
Couldn't we rename another type of file to a .nw or .graal using a script, then delete it?
deletefile() is not allowed to delete files in the levels folder,
It seems to depend upon the directory, not the file extension. So, unless you could rename inside levels/, then it again wouldn't work.