On 2013-01-27 16:25, Sebastian Valenzuela wrote:
Hi list,

My Pd patch creates and saves new audio files to a designated folder on
my desktop. I would like to have Pd delete these files every time I open
my patch ([loadbang]).

I've heard the [shell] object is a possibility, but i'm not too keen on
terminal commands or how they will pertain to [shell]...

Can anyone please give me an example of a command I would send to
[shell] to delete all files within a specified folder on my desktop? If
this isn't the best way to do it, is there another possibility through Pd?


You can use pdlua for this kind of thing.
See the attached patch. Right-click inside the [deletefile] object to open deletefile.pdlua in an editor.

Martin

#N canvas 398 519 752 300 10;
#X obj 153 109 deletefile;
#X msg 153 64 delete /home/martin/pd_patches/test.xxx;
#X obj 153 143 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X text 175 142 outputs 1 on success;
#X connect 0 0 2 0;
#X connect 1 0 0 0;
--[[ 

--deletefile
--  Symbol input is name of file to delete
-- Martin Peach 20130127
--]]

-- Pd class

local deletefile = pd.Class:new():register("deletefile")

function deletefile:initialize(name, atoms)
  self.inlets = 1
  self.outlets = 1
  return true
end

function deletefile:in_1_delete(atom)
  pd.post(type(atom[1]))
  if type(atom[1])=="string" then
    --self:outlet(1, "symbol", {atom[1]})
    f = io.open(atom[1], "r")
    if (f == nil) then
      pd.post("can't open " .. atom[1])
    else
      pd.post("deleting " .. atom[1])
      result = os.remove(atom[1])
      if (result) then q = 1
      else
        q = 0
      end
      self:outlet(1, "float", {q})
    end
  else
    pd.post("need a file name")
  end
end
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to