Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
roadrunner116

Filemanipulation from script

Question

Hi,

I'm trying to remove a folder and a file from my Update Script before downloading the new stuff. Somehow the way I'm trying I don't have the right permissions. What am I doing wrong.

-- remove old
local ok, err = pcall(shell.execute,"cd..")
if not ok then
	print("Problem: ",ok,err,computer.freeMemory())
end

local ok, err = pcall(shell.execute,"rm sg")
if not ok then
	print("Problem: ",ok,err,computer.freeMemory())
end


local ok, err = pcall(shell.execute,"rm autorun.lua")
if not ok then
	print("Problem: ",ok,err,computer.freeMemory())
end

Thanks!

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

local ok, err = pcall(shell.execute,"cd..")

 

There's your problem. There should be a space after the cd, like so:

 

local ok, err = pcall(shell.execute,"cd ..")

 

 

Assuming you are not in the root directory (/) , in which case you can't go up a level(which is what two periods do), so that won't work.

Link to post
Share on other sites
  • 0

cd.. is a special case that only works in DOS/Windows. The proper way to write it, as said above, is cd .. (cd is the command name, and .. is the single argument to the command). As far as I know cd .. does nothing if the current directory is /, at least it shouldn't cause any errors and such.

Link to post
Share on other sites
  • 0

Try cd / instead so if it is in root it will stay there, if it isn't it will go straight to root.

 

Also avoid shell.run("rm ") because there is an API method to do it and, while yes it is miniscule, it improves performance of the script and is just good practice.

Link to post
Share on other sites
  • 0

Sorry, I was away for a week.

 

Thanks for your replys, now it works.

 

 

Try cd / instead so if it is in root it will stay there, if it isn't it will go straight to root.

 

Also avoid shell.run("rm ") because there is an API method to do it and, while yes it is miniscule, it improves performance of the script and is just good practice.

 

Which method are you referring to?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.