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

Copy Folder and Sub folder with ruby

For general discussion related FlowStone

Copy Folder and Sub folder with ruby

Postby cglism » Fri Jun 14, 2019 8:34 am

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 9380 times
cglism
 
Posts: 2
Joined: Wed Jun 04, 2014 7:20 am

Re: Copy Folder and Sub folder with ruby

Postby trogluddite » Fri Jun 14, 2019 5:03 pm

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!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Copy Folder and Sub folder with ruby

Postby cglism » Fri Jun 14, 2019 11:36 pm

thank you trogluddite . robocopy it work :D :D
cglism
 
Posts: 2
Joined: Wed Jun 04, 2014 7:20 am

Re: Copy Folder and Sub folder with ruby

Postby trogluddite » Sat Jun 15, 2019 12:28 am

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!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK


Return to General

Who is online

Users browsing this forum: Google [Bot] and 62 guests