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

How to scan all directories for .DS_Store and delete it when found.

Started by Techman749, 19 January 2015 - 06:29 PM
Techman749 #1
Posted 19 January 2015 - 07:29 PM
Hello!

I was wondering how to make a computer scan all files in it's "HDD" and delete any file that is named ".DS_Store" I work from a Mac and it's so annoying when you are working on a program, that loads APIs and crashes because it was trying to load .DS_Store as an API.

I used to know how to do this, but I left Minecraft for 3 months for school and other personal matters.

Thanks in advance for your help!
Lignum #2
Posted 19 January 2015 - 08:03 PM

local function cleanDir(dir)
   local files = fs.list(dir) --# Get all files in our folder.
   for _,v in ipairs(files) do
	  if fs.isDir(fs.combine(dir, v)) then
		 cleanDir(fs.combine(dir, v)) --# We found another directory, so use recursion to clean that directory as well.
	  end
   end

   if fs.exists(fs.combine(dir, ".DS_Store")) then
	  fs.delete(fs.combine(dir, ".DS_Store")) --# Delete .DS_Store if it exists.
   end
end

cleanDir("/")

That should get the job done. However, I must ask: Why is your program loading .DS_Store in the first place?
Techman749 #3
Posted 19 January 2015 - 08:14 PM
The program loads whatever is in the Apis folder my os is using, whenever I go to that folder to add another API, my Mac decides to put a .DS_Store file in there. I'm not trying to load .DS_Store as an API.

Anyways, Thanks for the help!
Lignum #4
Posted 19 January 2015 - 09:21 PM
Oh alright then. You're welcome.
ByteMe #5
Posted 19 January 2015 - 10:23 PM
I wouldn't delete that if I was you. Well as long as all the folders and files in that place have no special attributes then you should be fine.
Edited on 19 January 2015 - 09:24 PM
Bubba #6
Posted 21 January 2015 - 07:37 AM
Why not just filter out .DS_STORE when you go to load something instead constantly deleting it? That would be both easier and more efficient.
Edited on 21 January 2015 - 06:37 AM
Rougeminner #7
Posted 25 January 2015 - 04:35 PM
mac osx will simply replace this file as it is apples debug file i belive in the new OS X which i am running that the file becomes pretty invisible why does.DS_store bother your computer programs?
Bubba #8
Posted 25 January 2015 - 06:30 PM
mac osx will simply replace this file as it is apples debug file i belive in the new OS X which i am running that the file becomes pretty invisible why does.DS_store bother your computer programs?

The .DS_store file is only invisible to the finder. It is quite visible when you get the contents of a directory via a program (for example, a ComputerCraft program).
Xtansia #9
Posted 26 January 2015 - 02:03 AM
Why not just ignore all files that begin with a dot when trying to load?
ByteMe #10
Posted 26 January 2015 - 10:12 PM
mac osx will simply replace this file as it is apples debug file i belive in the new OS X which i am running that the file becomes pretty invisible why does.DS_store bother your computer programs?
It's not their debug file, .DS_Store (short for Desktop Services Store) is the proprietary format created by OS X to store custom attributes of a folder such as the position of icons or the choice of a background image.
Techman749 #11
Posted 27 January 2015 - 09:36 PM
mac osx will simply replace this file as it is apples debug file i belive in the new OS X which i am running that the file becomes pretty invisible why does.DS_store bother your computer programs?

When I have my OS load anything in the apis folder, sometimes there will be the .DS_Store file in there. So the OS will try to load the .DS_Store file as an API, and crash.

Why not just ignore all files that begin with a dot when trying to load?
Deleting the file on startup helps prevent clutter, and keeps the size of the entire OS as small as I can get it. Also, I get very OCD when I see that file in there, so it helps to have my program delete it every time it's ran.

Offtopic: Love your ccEmuRedux Emulator, tomass1996! It's so good! I love using it when working on my programs!

My question has been successfully answered, Thanks to everyone who helped!
Edited on 27 January 2015 - 08:41 PM
Rougeminner #12
Posted 26 February 2015 - 10:19 PM
Well. i have some code that will make you and your mac happy if you would like me to pm it to you on your account page