File Handling

For general discussion related FlowStone
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Post by RJHollins »

cool ...

Is there a way to RENAME a file [using RUBY] ?
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: File Handling

Post by Nubeat7 »

yes, just updated the list above..
for more watch here:
http://ruby-doc.org/core-1.9.3/File.html
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Post by RJHollins »

Thanks for the LINK. Was having trouble finding the Ruby 1.9.3.

BookMarked 8-)
S1User
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Post by S1User »

That's great. Now I just need to study Ruby to find out how to trigger subs with those code lines.

I know how to push strings in and out with "@" I/O, but not yet clear on how to trigger a Ruby sub on demand.

Ah... wait... I think I see. Just replace my modules with a Ruby module and those things will just run.

Great. Off to give it a go.
S1User
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Post by S1User »

Oh man. :shock: I've been working way too hard not using Ruby modules. This below is much cleaner than the rats nest of primitives I had doing the same thing before.

You guys are great.

Schematic: http://i.imgur.com/ynRhihi.png
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Post by RJHollins »

Back to an issue I'm having :cry:

It seems FS RUBY does not have the FileUtils class.

What I'm trying to do is:

1. Copy a file to a new dest folder ... then,

2. Re-name the new [copied] file.

3. Insuring that the original file remains intact at original location.

I've used the posted 'File.rename(@old_name, @new_name)' , but it is removing the original file :roll:

Note: The goal. I have to make copies of a single file and rename them as new files in a new folder. There could be a dozen or more copies]. I'm using a filename list to increment through in the rename process.

Note 2. I also tried the EXEC primitive to do the copy. I can't seem to get that to work.

I suck :oops: :twisted:
User avatar
Walter Sommerfeld
Posts: 250
Joined: Wed Jul 14, 2010 6:00 pm
Location: HH - Made in Germany
Contact:

Re: File Handling

Post by Walter Sommerfeld »

Hi,

here a method 4U i got from DWB (hope he don't mind)

Code: Select all

def copy_file(src,dest)
    File.open(src, 'rb') do |s|
        File.open(dest, 'wb', s.stat.mode) do |f|
            IO.copy_stream(s, f)
        end
    end
end

Keep on Doing!
Walter
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Post by RJHollins »

Thanks Walter [....and DWB]

I'll give this a go when I get back.

Appreciate.
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Post by RJHollins »

hmmm ... no luck getting this code working ... as yet. :|
User avatar
Walter Sommerfeld
Posts: 250
Joined: Wed Jul 14, 2010 6:00 pm
Location: HH - Made in Germany
Contact:

Re: File Handling

Post by Walter Sommerfeld »

Here u go...

Have Phun ;-)

Warning: Dest will be overwritten and path must exist...
Attachments
...I think U need Admin rights because of ProgFiles path 4 this test schematic:
...I think U need Admin rights because of ProgFiles path 4 this test schematic:
copy file fom DWB in ruby (sun mod).png (288.42 KiB) Viewed 19330 times
copy file fom DWB in ruby (sun mod).fsm
(1.31 KiB) Downloaded 866 times
Post Reply