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.