K
KONTRA Gergely
Hi!
Can I specify how strings are printed, when using the p function?
I mean with ' or with " ?
---
During running a little program, which detects files with the same
content, I get a ruby bug:
processing dir c:\WINDOWS\SYSTEM\VMM32
processing dir c:\WINDOWS\SYSTEM\CatRoot
processing dir
c:\WINDOWS\SYSTEM\CatRoot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}
processing dir
c:\WINDOWS\SYSTEM\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
processing dir c:\WINDOWS\SYSTEM\sfp
processing dir c:\WINDOWS\SYSTEM\sfp\tempcats
processing dir c:\WINDOWS\SYSTEM\DirectX
processing dir c:\WINDOWS\SYSTEM\DirectX\Migrate
processing dir c:\WINDOWS\SYSTEM\DirectX\Dinput
processing dir c:\WINDOWS\SYSTEM\Drivers
Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory -
c:\WINDOWS\SYSTEM
\DirectX\Migrate\vjoyd.vxd
same.rb:4: [BUG] rb_sys_fail() - errno == 0
ruby 1.8.0 (2003-08-04) [i386-mingw32]
abnormal program termination
It is a self-compiled ruby.
The program follows: BTW: can anybody simplify it, or make it clearer.
It seems to work, but I think it can be written more compact...
(I wrote it in python (I don't know python, I just tried it), and the
outputs are different.)
============================================================
$files=Hash.new { [] } # {theSize=>[[fn1,fn2],[fn3]]} fn1 and fn2 have same content
def equalFiles? fn1, fn2
f1=File.open fn1,'r'
f2=File.open fn2,'r'
while chunk1=f1.read(512)
chunk2=f2.read(512)
return false if chunk1!=chunk2
end
return true
end
def processDir(dir='.')
$stderr.print "processing dir #{dir}\n"
Dir.foreach(dir) {|f|
begin
next if f=='.' or f=='..'
fn=dir+'\\'+f
if File.directory? fn
fnprocessDir fn
else
elsesize=File.size fn
fnif
fnif ($files[size]).each{|fn2| # process each segment
segment if equalFiles? fn,fn2[0]
fn2 #fn2.replace fn2.push(fn)
fn fn2<<=fn
fn break nil
nil end
end }
end $files[size]<<=[fn]
fnend
end
rescue
$stderr.print "Ooops #{fn}: #$!\n"
end
}
end
processDir ARGV[0]
puts '='*60
$files.sort.each {|h|
size,arr_size=h
arr_size.each {|segment|
if segment.size>1
print "#{size} -> "
p segment
end
}
}
============================================================
Can I specify how strings are printed, when using the p function?
I mean with ' or with " ?
---
During running a little program, which detects files with the same
content, I get a ruby bug:
processing dir c:\WINDOWS\SYSTEM\VMM32
processing dir c:\WINDOWS\SYSTEM\CatRoot
processing dir
c:\WINDOWS\SYSTEM\CatRoot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}
processing dir
c:\WINDOWS\SYSTEM\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
processing dir c:\WINDOWS\SYSTEM\sfp
processing dir c:\WINDOWS\SYSTEM\sfp\tempcats
processing dir c:\WINDOWS\SYSTEM\DirectX
processing dir c:\WINDOWS\SYSTEM\DirectX\Migrate
processing dir c:\WINDOWS\SYSTEM\DirectX\Dinput
processing dir c:\WINDOWS\SYSTEM\Drivers
Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory -
c:\WINDOWS\SYSTEM
\DirectX\Migrate\vjoyd.vxd
same.rb:4: [BUG] rb_sys_fail() - errno == 0
ruby 1.8.0 (2003-08-04) [i386-mingw32]
abnormal program termination
It is a self-compiled ruby.
The program follows: BTW: can anybody simplify it, or make it clearer.
It seems to work, but I think it can be written more compact...
(I wrote it in python (I don't know python, I just tried it), and the
outputs are different.)
============================================================
$files=Hash.new { [] } # {theSize=>[[fn1,fn2],[fn3]]} fn1 and fn2 have same content
def equalFiles? fn1, fn2
f1=File.open fn1,'r'
f2=File.open fn2,'r'
while chunk1=f1.read(512)
chunk2=f2.read(512)
return false if chunk1!=chunk2
end
return true
end
def processDir(dir='.')
$stderr.print "processing dir #{dir}\n"
Dir.foreach(dir) {|f|
begin
next if f=='.' or f=='..'
fn=dir+'\\'+f
if File.directory? fn
fnprocessDir fn
else
elsesize=File.size fn
fnif
fnif ($files[size]).each{|fn2| # process each segment
segment if equalFiles? fn,fn2[0]
fn2 #fn2.replace fn2.push(fn)
fn fn2<<=fn
fn break nil
nil end
end }
end $files[size]<<=[fn]
fnend
end
rescue
$stderr.print "Ooops #{fn}: #$!\n"
end
}
end
processDir ARGV[0]
puts '='*60
$files.sort.each {|h|
size,arr_size=h
arr_size.each {|segment|
if segment.size>1
print "#{size} -> "
p segment
end
}
}
============================================================