I have expanded zip files for many different downloads from Thingiverse and similar.
I want to just tidy up my storage and delete either the expanded folder or archive file for the ones I’ve extracted, but I haven’t done them all.
So my logic is if a filename matches the next filename with .zip extension, delete one or the other.
Here are a couple of examples. I have hundreds of these in my Downloads folder alone…
drwx------@ Simple_Sugar_Bowl_with_spoon_1848999
-rw-r–r–@ Simple_Sugar_Bowl_with_spoon_1848999.zip
drwx------@ Skull Bowl widened - 6181744
-rw-r–r–@ Skull Bowl widened - 6181744.zip
So this is what I’ve been playing with:
aname=“xxx”; ls | while read bname; do if [ “$bname” -eq “$aname.zip” ] ; then rm -r $bname ; fi ; done
Pretty simple, but I keep getting syntax errors that I can’t nail down. The native shell on Mac OS is zsh, but I’ve also tried csh and bsh which I know really well from a past life in the *IX world.
I did it by pasting the contents of @eflyguy’s post, then adding “ can you help me finish this project? I’d also like to add a flag that executes the deletes. If the flag is not present it simply outputs what it would do if the flag were present, as a safety measure”
It took about 1 second. It’s a new world.
As with any AI code, look at it carefully and make sure you know what’s doing but skimming it, it looks pretty good. This kind of simple coding question is a piece of cake for LLM’s.
They’re coming. We have a telescope and we can see their ships headed our way. They will be here soon. We just don’t know if they will be friendly or hostile.
If chat-gpt every creates a book titled “To Serve Man”, you better double-check the table of contents.
That doesn’t work. Formatting is wrong, quotes are not standard, all kinds of issues with it. No matter, just wanted to report back. It’s not a huge priority so I’ll share what I end up with.
Regarding automator, it’s pretty much useless here as well. I know it, I’ve used it, it’s great at what it’s designed for.
Back when I used to do this for a living, I would just write C code to solve problems like this. I’ve played with perl but it came long after I got out of that game. I know shell can do it, I just need to figure out the syntax.
For the inner geek - I then took it to the next level, and scripted out a way to look inside the .zip archives I had not expanded into folders for .svg, .stl or .dxf files, and moved them over to the same folder as well…
for zip in *.zip ; do
unzip -l “$zip” | grep -E “.STL|.stl|.svg|.SVG|.dxf|.DXF” > NULL
if test $? = 0 ; then mv “$zip” design\ files ; fi
done
(just realized - the forum removed the back slashes in front of every file extension in the grep command)