I actually want to copy the contents of all files that is in a
particular directory into a new directory.The new files should be of a
specific size (2MB)and each with a new name (randomly assigned).
My Current Code looks,
testdir = "K:/test"
# Iterating over each entry
Dir.entries(testdir).each do |file|
Thanks ,the link to the resource you gave was very helpful.
I can copy the files now, but when i am putting a restriction on a file size it doesn't care about the restriction and copies beyond the placed restriction.. My program logic is probably incorrect..! Here is the 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("K:/testresult/test1.txt",'a') do |dest|
# Trying to put a restriction here if size of file is < 50
if File.size("K:/testresult/test1.txt")<50
dest.puts(line)
else
File.open("K:/testresult/test2.txt",'a')
dest.puts(line)
end
end
end end
It isn't giving any error message works fine but it is copying the file contents even if the file.size is beyond what i specified <50