Copy Folder and Sub folder with ruby

For general discussion related FlowStone
Post Reply
cglism
Posts: 2
Joined: Wed Jun 04, 2014 7:20 am

Copy Folder and Sub folder with ruby

Post by cglism »

i try to copy folder and sub with ruby code in external it work
in .rb code is simple
require 'fileutils'
FileUtils.cp_r "C:/Test/.", "C:/out"

when i try in flowstone i cant what my wrong?

require 'FileUtils'
def event i
if i=='click'
FileUtils.cp_r(@src_path, @out_path)
end
end
Attachments
SNAG-0024.jpg
SNAG-0024.jpg (105.09 KiB) Viewed 10642 times
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Copy Folder and Sub folder with ruby

Post by trogluddite »

Welcome to the forum, cglism.

Using the Ruby standard libraries via "require" and Gems does not work as standard Ruby in FlowStone, unfortunately.

The first difference is that the FS installation does not include the standard libraries. However, from the error message, I am guessing that you already modified $LOAD_PATH to fix this.

The second difference is that libraries cannot be used which include compiled C++ extensions, only those which are coded using pure Ruby. But I don't think this is the problem - the FileUtils source code is Ruby and I can't see any other "requires" in the code.

The third difference is that the Encoding class for Strings only allows ASCII Strings. None of the UTF encodings are available - and this is what the error message is saying. So it seems that either the FileUtils source file is UTF encoded, or that within the FileUtils methods, some String encoding conversions are used.

Unfortunately, because Encoding is a "core" class compiled into FlowStone's custom Ruby interpreter, there is nothing that can be done to change this.

The easiest alternative would be to use the xcopy or robocopy commands of the Windows cmd shell via the Ruby system method. That would look something like this...

Code: Select all

# NB: source and destination are wrapped in quotes to allow space characters in the paths.
system("robocopy \"#{source}\" \"#{destination}\" /e")
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
cglism
Posts: 2
Joined: Wed Jun 04, 2014 7:20 am

Re: Copy Folder and Sub folder with ruby

Post by cglism »

thank you trogluddite . robocopy it work :D :D
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Copy Folder and Sub folder with ruby

Post by trogluddite »

You're welcome!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Post Reply