# Libs for high-level file processing?

**URL:** <https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757>\
**Category:** Ruby\
**Created:** [November 20, 2007, 12:15pm UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757 "2007-11-20T12:15:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [November 20, 2007, 12:15pm UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757/1 "2007-11-20T12:15:30Z")

</div>

Is there anything you comp.lang.ruby readers would recommend that would  
abstract away things like “if file load fails” or “if file not found” or  
“index of all .xml -files in the subdirs”?

I can do the rescue patrol -mission, but time is running out! Lost on  
the Apache mountain. I am not sure my squad will get us there on time…

Not looking for anything big, preferably small and simple (ie.  
practical).

Thanks  
Csmr

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [November 20, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757/2 "2007-11-20T16:07:23Z")

</div>

-------- Original-Nachricht --------

> Datum: Tue, 20 Nov 2007 20:15:04 +0900  
> Von: Casimir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Libs for high-level file processing?

> Csmr  
> Dear Casimir,

mmh - maybe rio can help?

[http://rio.rubyforge.org/](http://rio.rubyforge.org/)

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [November 20, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757/3 "2007-11-20T17:51:28Z")

</div>

2007/11/20, Casimir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Is there anything you comp.lang.ruby readers would recommend that would  
> abstract away things like “if file load fails” or “if file not found” or  
> “index of all .xml -files in the subdirs”?

I am not sure what you are missing. You can do

File.open(“foo”) do |io|  
end resuce nil

if File.exists? “foo”

xml\_files = Dir[“bas/\*\*/\*.xml”]

Which is pretty small I’d say. What am I missing?

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [November 21, 2007, 10:02am UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757/4 "2007-11-21T10:02:05Z")

</div>

Casimir P wrote:

> ```
> savesubpath = path.split("/").last
> saveresized = savetargetstr.to_s + "/" + path.split("/").last + "/" + 
> 
> ```
> 
> (m+1).to\_s + “fullsize” + imageFormat  
> #and then write and FAIL…  
> #Double slash kills…  
> #Or directory doesnt exist!

I think the lines above are more easily handled if you use the methods  
in the core File library, such as File.basename etc. Much to choose from  
there.

Best regards,

Jari W.

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [November 20, 2007, 11:21pm UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757/5 "2007-11-20T23:21:49Z")

</div>

> -------- Original-Nachricht --------
> 
> > Datum: Tue, 20 Nov 2007 20:15:04 +0900 Von: Casimir  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) An: removed\_email\_address@domain.invalid  
> > Betreff: Libs for high-level file processing?
> 
> > Is there anything you comp.lang.ruby readers would recommend that would  
> > abstract away things like “if file load fails” or “if file not found”  
> > or “index of all .xml -files in the subdirs”?

On Tue, 20 Nov 2007 10:06:36 -0500, Axel E. wrote:

> Dear Casimir,  
> …  
> mmh - maybe rio can help? [http://rio.rubyforge.org/](http://rio.rubyforge.org/)

On Tue, 20 Nov 2007 11:49:30 -0500, Robert K. wrote:

> Which is pretty small I’d say. What am I missing?  
> I admint! I is dummy! IT’s easy! 8)

Dir[‘/home/kasbah/_.jpg’ && '/home/kasbah/_.png’].sort!.each { |f| puts  
f.to\_s }

But then its not that short:

if File.exists? $imgSourcePathStr  
if File.exists? $imgDestPathStr  
indexedDirs = indexImagesInDirs  
($imgSourcePathStrs, $imgDestPathStr)  
else  
puts “no dest!”  
exit  
end  
else  
puts “no src!”  
exit  
end

indexedDirs.each { |one|  
path=one[0]  
num=0  
one.flatten!.length \< 8 ? num = (one.length.to\_i-1) : num = 7  
num.times { |m|  
puts “converting (” + (m+1).to\_s + “/” + num.to\_s + “)”  
imgname = one[(m+1)]  
savesubpath = path.split(“/”).last  
saveresized = savetargetstr.to\_s + “/” + path.split(“/”).last + “/”  
+  
(m+1).to\_s + “fullsize” + imageFormat  
#and then write and FAIL…  
#Double slash kills…  
#Or directory doesnt exist!  
#Its all too complicated ☹  
#I is dum!  
}  
}

Csmr

---

<div class="post-metadata">

**Author:** ![Casimir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Casimir](https://www.ruby-forum.com/u/Casimir)\
**Post date:** [November 21, 2007, 10:35am UTC](https://www.ruby-forum.com/t/libs-for-high-level-file-processing/120757/6 "2007-11-21T10:35:26Z")

</div>

> Casimir P wrote:
> 
> > ```
> > saveresized = savetargetstr.to_s + "/" + path.split("/").last + "/" + 
> > 
> > ```
> > 
> > (m+1).to\_s + “fullsize” + imageFormat  
> > #and then write and FAIL…  
> > #Double slash kills…  
> > #Or directory doesnt exist!

Jari W. wrote:

> I think the lines above are more easily handled if you use the methods  
> in the core File library, such as File.basename etc. Much to choose from  
> there.

Yes. I was oblivious to File.basename which was exactly what I was  
looking for. Thank you for pushing me in the right direction!

But I was not waste of time! I twas gathering cases for file ops. IT’s  
easy! 8)

Here’s what I got, minimal case plan

- Open file
- Create file that doesn’t exist, open
- Save file
- Overwrite file
- Dir doesnt exist, create
- get filename from path str (file.basename).
- get the sub dir file is (“deepest” dir)
- remove dbl slashes (etc crap).
- nonrelative dir (remove /dir1/…/dir1/ etc.)

I was looking for guide covering these on google. Didn’t find one. I  
guess I will have to write a micro guide to these. 8)

Csmr
