Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Ruby question-delete files by their suffix; possible?

For general discussion related FlowStone

Ruby question-delete files by their suffix; possible?

Postby kortezzzz » Fri Oct 28, 2016 8:30 pm

Hi,

I have this code which is based tulamide's suggestion.
Code: Select all
def event i
   if i == "do_it"
      File.delete(@path, File.dirname(@path))
   end
end


This ruby code deletes a given file from the H.D. if you feed it's string input with the full file's name+location
(for instance: "C:\Users\kortezzzz\Pictures\bla bla.png") and push the trigger input. The problem is that it won't delete as many files as you need (based on their suffix) if you feed it's string input with "*.something" method like the windows "CMD" command line does (for instance: "C:\Users\kortezzzz\Pictures\*.png"). Is there any way to force ruby do it?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question-delete files by their suffix; possible?

Postby KG_is_back » Fri Oct 28, 2016 9:00 pm

Yes, it can be done, actually very easily.

Code: Select all

def event(i,v,t)
if i == "do_it"
paths=Dir.glob(@path) #makes an array of all files which match shell-styled pattern (for example "C:/*.doc")
paths.each{|path| #iterates through the array and deletes files one by one
File.delete(path, File.dirname(path))

}
end
end


EDIT: I messed up the parentheses... fixed now
Last edited by KG_is_back on Fri Oct 28, 2016 9:43 pm, edited 1 time in total.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Ruby question-delete files by their suffix; possible?

Postby kortezzzz » Fri Oct 28, 2016 9:32 pm

Thanks for the super fast reply, KG :)

For some reason, your code gives an error message on line no. 6
Seems like I'm doing something wrong. Uploaded my little schematic here for testing.

Thanks a lot!
Attachments
(ruby- delete by preffix).fsm
(588 Bytes) Downloaded 1311 times
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question-delete files by their suffix; possible?

Postby kortezzzz » Sat Oct 29, 2016 9:18 am

Sorry KG, but it's not working for me even after your edit. Can you please take a look at the schematic? Perhaps FS ruby doesn't support that feature?
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question-delete files by their suffix; possible?

Postby kortezzzz » Sat Oct 29, 2016 11:02 am

Found other cool, easy and green way to it by calling "CMD" feature (using the "Exec" primitive). This combination can do so much more and it's easy to use as well.

Thanks anyway, KG :D
Attachments
(delete any file_green).fsm
(1.7 KiB) Downloaded 1338 times
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Re: Ruby question-delete files by their suffix; possible?

Postby rewiredrecords » Wed May 19, 2021 10:45 pm

kortezzzz wrote:Found other cool, easy and green way to it by calling "CMD" feature (using the "Exec" primitive). This combination can do so much more and it's easy to use as well.

Thanks anyway, KG :D


Excellent! Thanks mate. Just what I needed :D
rewiredrecords
 
Posts: 8
Joined: Wed Nov 27, 2019 6:11 pm


Return to General

Who is online

Users browsing this forum: No registered users and 66 guests

cron