Page 1 of 1

Copy Folder and Sub folder with ruby

PostPosted: Fri Jun 14, 2019 8:34 am
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

Re: Copy Folder and Sub folder with ruby

PostPosted: Fri Jun 14, 2019 5:03 pm
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")

Re: Copy Folder and Sub folder with ruby

PostPosted: Fri Jun 14, 2019 11:36 pm
by cglism
thank you trogluddite . robocopy it work :D :D

Re: Copy Folder and Sub folder with ruby

PostPosted: Sat Jun 15, 2019 12:28 am
by trogluddite
You're welcome!