How to Delete files using Shell
Hi,
I`m having problems to delete files from my computer using shell object. I have tested many different messages to make it happens but with no luck. Which is the right message to send to shell if I want to delete a specific file?
Let`s say this is the file path: "MacOS :/Users/a/Documents/Max MSP_Projects/Podcaster/Presets/teddd.json"
Thanks in advance!
as first - if you are running any restrictive MacOS, you must give
full disk access in settings to app in order to let it delete files.
in normal circumstances, message :
rm "/Users/a/Documents/Max MSP_Projects/Podcaster/Preset/teddd.json"
user path can be shorted using tide:
"~/a/Documents/Max MSP_Projects/Podcaster/Preset/teddd.json"
path you wrote is not existing.
if a file nees root access to be deleted, you need sudo rm
echo 'password' | sudo -S rm "~/a/Documents/bla bla.txt"
or penter 'password'
and then shell will execute next sudo .....
Thanks Source Audio!
But any of the metioned messages worked to delete the files.
Should I use this message in case root access is needed? echo 'password' | sudo -S rm "~/a/Documents/bla bla.txt"
Why bla bla.txt?
bla bla is just example, you put your real file name in.
also the ‘password’ should be your real password, quotas are needed only if password has space inside.
Thanks Source Audio. I will check it out.
take care with sudo rm message to shell.
a little mistake can wipe all your hard drives,
in first place if you use sudo rm -rf (force recursive deletion)
ok thanks for the advice. I could not make it work yet.
it is not possible to provide further help without more details.
you answered previousy that
"any of the metioned messages worked to delete the files"
in that case it is only sudo execution that you can't make to work, or ?
Reason could be anyhing, starting with possibility that you don't have
administrative acount at all, or anyting else, including wrong path,
syntax , files are protected by SIP, whatever.
You also didn't mention which OS you use, if SIP is enabled or not etc.
and if max has full disk access rights enabled in security settings.
I'd say if you can delete files you need using plain rm message, than let it be with sudoing.
I could not make it work even using sudo. I`m on OS Monterey. SIP is disabled. Administrative account. Max has full access. Not sure what else to test...
post your patch with exact message you send to shell.
This is the patch.
1st prblem is that if you try to use sudo with wrong password and path,
shell will hang.
2nd your path is wrong
if your user name is a and password xxxxxxx
then this is wrong.

eiher /Users/a/ or ~/
~/ is replacement for user folder.
if your passwor is xxxxxxx , this should be correct message :
echo xxxxxxx | sudo -S rm ~/Documents/'Max MSP_Projects'/Podcaster/Presets/teddd.json
Now it worked but only for 1 file, if I create again a new file with the same filename it works. But I cannot make it works with other files. Sudo was not necessary. It`s weird.
other file in same folder ?
~/Documents/'Max MSP_Projects'/Podcaster/Presets/
don't forget the rule - if any part of path (incluing file itself)
has space , you must enclose it with ' ' single quotes.
look at this example :
~/'AAA BBB'/CCC/'DDD EEE'/'file to delete.txt'
Yes other files in the same folder. It works for some files but don`t work for some others. I cannot find which is the pattern that make it works or not. It`s weird.
can you post few messages for files that don't work,
if it is not too private thing ?
maybe somethig in the file name breaks the path.
you caa also get info on that files to check if you are the owner.
If you are not, then you need sudo to wipe them.
Finally it started working properly, not sure why, but now it`s working. I`m using doble quotes always and it works on any case, even if there are blank spaces.
rm "/Users/a/Documents/'Max MSP_Projects'/Podcaster/Presets/Like This.json"
This way always works now.
Thanks a lot Source Audio! Your help is always really appreciated ;)
ok, glad it works, even that it shoud also work with
rm /Users/a/Documents/'Max MSP_Projects'/Podcaster/Presets/'Like This.json'
Does this shell object works for Windows too? I`m testing it on Windows but it does not work.
shell sits between max and functions, replacing terminal on mac or command prompt on windows.
commands and path forming differ between systems.
on winows one of commands to delete file is del
you may want to read del manual or description.
or powershell Remove-Item
I see. Let`s say the file path is C:/Users/Usuario/Desktop/My Patchers/resources/presets/April.json
Then for example this would be the commadn to delete a file on WIndows?
del "/Users/Usuario/Desktop/My Patchers/resources/presets/April.json"
I also tried using single quote around My Patchers but it does not work.
Im on Windows 10 now. Admin account
why don't you try instead of asking ?
most problems are related to specific max - shell relation when it comes to forming paths.
I don't have that all present in my brain, because I don't use windows at all, only make stuff for my customers that run it, from time to time.
dealing with windows paths was allways pain in the ass because of backslashes, but that changed somewhat in last shell release.
But I can't help you with that at the moment.
Have no windows machine at hand on the road.
Sure, I`ve already tried the example I posted before but it does not worked. It`s why I ask if this was the right way to request file deletion. I have tested many different ways but any of them worked. And not sure what else to try.
del "/Users/Usuario/Desktop/My Patchers/resources/presets/April.json"
that is by no means windows path.
you can start by using dropfile to get path to file,
if it does not work see if shell needs to convert path type to something else using conformpath.

also check if
del filepath works in shell, because old official del says
filedir del filename
P.S. it is none of them worked, not any of them worked,
which would mean ALL off them worked.
I think I got it working. That was the right command:
del "C:\\Users\\Usuario\\Desktop\\My Patchers\\resources\\presets\\April.json
you see ...
a bit of research and all ok.
thanks again