0

Hi,
I am having a problem when trying to restrict the size of the file to a certain size.
My aim is to create new files and each file of a specific size. I am creating these new files by copying the contents over to these new files from a particular directory.
Here is my Code,

Dir.entries(testdir).each do |file|
# Joining the path where the actual files are
   path = File.join testdir, file
           if File.file? path
             File.open path do |source|
            while (line=source.gets)
            File.open("L:/testresult/test1.txt",'a') do |dest|
              # Trying to put a restriction here on file size
              if File.size("L:/testresult/test1.txt")<50
                dest.puts(line)
              else
               File.open("L:/testresult/test2.txt",'a')
                  dest.puts(line)
                       end
                end            
            end

The above code doesn't give any error message but also doesn't care about the size of the file even if the size is >50 it will carry on copying the content to the same file.

There is something wrong with the current Logic.

I want it to go and create new file and copy the contents over if size >50 at any point while copying lines.

Thank you for reading , any help will be much appreciated.
Gear,

Edited by peter_budo: Adding code tags older thread

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Zoon
1

Hello,

Have you tried to print out the output of File.size()? Maybe it doesn't work like that :)

Also, please use code tags, it eases the reading and retains indents.

// Zoon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.