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?
6 posts
• Page 1 of 1
Ruby question-delete files by their suffix; possible?
Hi,
I have this code which is based tulamide's suggestion.
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?
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?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question-delete files by their suffix; possible?
Yes, it can be done, actually very easily.
EDIT: I messed up the parentheses... fixed now
- 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?
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!
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 1313 times
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question-delete files by their suffix; possible?
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?
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question-delete files by their suffix; possible?
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
Thanks anyway, KG
- Attachments
-
- (delete any file_green).fsm
- (1.7 KiB) Downloaded 1340 times
-
kortezzzz - Posts: 763
- Joined: Tue Mar 19, 2013 4:21 pm
Re: Ruby question-delete files by their suffix; possible?
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
Excellent! Thanks mate. Just what I needed
- rewiredrecords
- Posts: 8
- Joined: Wed Nov 27, 2019 6:11 pm
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 59 guests