Page 2 of 3

Re: File Handling

Posted: Thu Mar 10, 2016 9:04 pm
by RJHollins
cool ...

Is there a way to RENAME a file [using RUBY] ?

Re: File Handling

Posted: Thu Mar 10, 2016 9:11 pm
by Nubeat7
yes, just updated the list above..
for more watch here:
http://ruby-doc.org/core-1.9.3/File.html

Re: File Handling

Posted: Thu Mar 10, 2016 9:47 pm
by RJHollins
Thanks for the LINK. Was having trouble finding the Ruby 1.9.3.

BookMarked 8-)

Re: File Handling

Posted: Thu Mar 10, 2016 9:48 pm
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.

Re: File Handling

Posted: Thu Mar 10, 2016 11:57 pm
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

Re: File Handling

Posted: Fri May 13, 2016 6:44 am
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:

Re: File Handling

Posted: Fri May 13, 2016 11:38 am
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

Re: File Handling

Posted: Fri May 13, 2016 5:19 pm
by RJHollins
Thanks Walter [....and DWB]

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

Appreciate.

Re: File Handling

Posted: Sat May 14, 2016 12:37 am
by RJHollins
hmmm ... no luck getting this code working ... as yet. :|

Re: File Handling

Posted: Sat May 14, 2016 11:40 am
by Walter Sommerfeld
Here u go...

Have Phun ;-)

Warning: Dest will be overwritten and path must exist...