L
Li Chen
Hi folks,
I write two srcipts to check files in a given directory. Version 1 uses
regular expression and works but I cann't find the size for each file.
Version 2 uses Ruby built-in File.file? method but it doesn't work at
all. I wonder what is going on with my scripts?
Thank you,
Li
#######Version 1:
path='c:\path\to\folder'
Dir.open(path).each do |file|
if file=~/(\w+|d+).(\d{3,})/
puts file
puts File.size(file)# this line doesn't work
file_number+=1
end
end
puts
puts 'Files',path
puts 'File number',file_number
#######Version2
path='c:\path\to\folder'
Dir.open(path).each do |file|
if File.file?(file)
puts file
puts File.size(file)
file_number+=1
end
end
puts
puts 'Files',path
puts 'File number',file_number
I write two srcipts to check files in a given directory. Version 1 uses
regular expression and works but I cann't find the size for each file.
Version 2 uses Ruby built-in File.file? method but it doesn't work at
all. I wonder what is going on with my scripts?
Thank you,
Li
#######Version 1:
path='c:\path\to\folder'
Dir.open(path).each do |file|
if file=~/(\w+|d+).(\d{3,})/
puts file
puts File.size(file)# this line doesn't work
file_number+=1
end
end
puts
puts 'Files',path
puts 'File number',file_number
#######Version2
path='c:\path\to\folder'
Dir.open(path).each do |file|
if File.file?(file)
puts file
puts File.size(file)
file_number+=1
end
end
puts
puts 'Files',path
puts 'File number',file_number