This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gergo654's profile picture

Delete all files in the default directory

Started by gergo654, 05 March 2016 - 01:33 PM
gergo654 #1
Posted 05 March 2016 - 02:33 PM
Can Someone help me
how can i delete all files from the default directory?
Goof #2
Posted 05 March 2016 - 05:04 PM
Can Someone help me
how can i delete all files from the default directory?

What do you mean?
The default directory of a CC computer is /.
To remove all files type rm * when the computer is opened.
The rom directory is readOnly, which means that it is not possible to remove it.

I hope that helped
Edited on 05 March 2016 - 04:06 PM
ry00000 #3
Posted 05 March 2016 - 06:18 PM
or do fs.delete("*") within a Lua interpreter or a program.


fs.delete("*")
Anavrins #4
Posted 05 March 2016 - 06:50 PM
or do fs.delete("*") within a Lua interpreter or a program.
That will only delete the file named *.
FS doesn't deal with wildcards, the shell does.
Edited on 05 March 2016 - 05:51 PM
ry00000 #5
Posted 05 March 2016 - 07:57 PM
Oh. Didn't know that.
hbomb79 #6
Posted 06 March 2016 - 09:17 AM
If you want to delete all files in the root directory of your computer (excluding rom and other read only directories) from within a program you could try something along these lines (untested as am on phone)


for _, file in ipairs( fs.list("") ) do --# loop every file and subdirectory
  if not fs.isReadyOnly( file ) and not fs.isDir( file ) then --# your question said 'all files'. If you want to delete all subdirectories too remove the 'and not fs.isDir( file )' from that if statement. The rest of the IF statement makes sure we don't try to delete the rom or other protected directories (causes crash).
    fs.delete( file ) --# delete the file
  end
end

Apologies if this doesn't work 100% as I mentioned I am on my phone and cannot test.
Edited on 06 March 2016 - 08:18 AM