MuppetGate Posted March 9, 2013 Share Posted March 9, 2013 Hello again. I wonder if someone could help out with a bit of Ruby scripting. I've written a workflow that deletes a list of files selected from Alfred. The problem is with the script; I can't get it to delete the files. ext = "{query}" fileNames = text.split("/t") filesDeleted = "" fileNames.each do |fileName| command = "rm -r " + fileName system(command) filesDeleted << fileName end print filesDeleted Everything else works okay apart from the system call. Any ideas as to what I've forgotten? ... Link to comment
jdfwarrior Posted March 9, 2013 Share Posted March 9, 2013 Hello again. I wonder if someone could help out with a bit of Ruby scripting. I've written a workflow that deletes a list of files selected from Alfred. The problem is with the script; I can't get it to delete the files. ext = "{query}" fileNames = text.split("/t") filesDeleted = "" fileNames.each do |fileName| command = "rm -r " + fileName system(command) filesDeleted << fileName end print filesDeleted Everything else works okay apart from the system call. Any ideas as to what I've forgotten? ... Have you tried commenting out the system command and just using puts or print to get the exact output of command? Make sure its creating the string correctly? Also, in the command string where you are creating 'rm -r '+filename, you might ought to modify it so that the output of fileName will be in quotes when the command is run so it will still function correctly if the path has a space in it (unless you already have it escaped) Link to comment
ctwise Posted March 9, 2013 Share Posted March 9, 2013 Hello again. I wonder if someone could help out with a bit of Ruby scripting. I've written a workflow that deletes a list of files selected from Alfred. The problem is with the script; I can't get it to delete the files. ext = "{query}" fileNames = text.split("/t") filesDeleted = "" fileNames.each do |fileName| command = "rm -r " + fileName system(command) filesDeleted << fileName end print filesDeleted Everything else works okay apart from the system call. Any ideas as to what I've forgotten? ... You can use the back ticks to run system commands. `rm -r "#{fileName}"` Your problem might be spaces in filenames. Hence the double quotes. Link to comment
MuppetGate Posted March 9, 2013 Author Share Posted March 9, 2013 Ah! Right, I've just tried printing and it appears that my split method isn't splitting on the the tab character. I need to play around with it some more I think. Link to comment
MuppetGate Posted March 9, 2013 Author Share Posted March 9, 2013 Deja vu. The fixes it. fileNames = text.split(" ") And I would have surely tripped over the 'spaces in filenames' thing within the next hour. Thanks for the suggestions! Link to comment
pittman Posted September 24, 2013 Share Posted September 24, 2013 I think the problem with the tabs was that it should be `\t` not `/t`. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now