Newbee: recursively converting LF to CRLF and vice versa

E

Elliott

Hello,

I'd like to recursively go through a bunch of directories and for text
file - convert any linefeed (LF) endings to carriage return line feeds
(CRLF). Ideally, I'd like to be able to do the conversion either way
and to distinguish from binary files (so that I don't bother doing any
changes to these files). Lastly, I'd like to package this utility as
a standalone .exe for windows for systems that don't have ruby on it.

I'm slowly going through the Picaxe book but I need to get this
utility done and I'd like to do it in Ruby if possible, rather than
resort to some other thing like Java (gasp). Can anyone provide me
some hints or at least some pointers to parts of Picaxe from which I
could assemble this functionality.

Anything info would be appreciated.

Elliott
 
M

Mark Hubbart

Hello,
=20
I'd like to recursively go through a bunch of directories and for text
file - convert any linefeed (LF) endings to carriage return line feeds
(CRLF). Ideally, I'd like to be able to do the conversion either way
and to distinguish from binary files (so that I don't bother doing any
changes to these files). Lastly, I'd like to package this utility as
a standalone .exe for windows for systems that don't have ruby on it.
=20
I'm slowly going through the Picaxe book but I need to get this
utility done and I'd like to do it in Ruby if possible, rather than
resort to some other thing like Java (gasp). Can anyone provide me
some hints or at least some pointers to parts of Picaxe from which I
could assemble this functionality.
=20
Anything info would be appreciated.

A few things to look at:

- The Find module searches recursively in directories, calling your
block of code for each file. Find it in the reference section.
- Scan for control characters in the file contents to determine
(usually) if it is binary or not. You could use a Regexp like
/[[:cntrl:]]/, which matches a single control character.
- The standalone exe can be made using RubyScript2EXE (by Erik Veen).
Find more info at http://www.erikveen.dds.nl/rubyscript2exe

HTH,
Mark
 
J

James Edward Gray II

Can anyone provide me
some hints or at least some pointers to parts of Picaxe from which I
could assemble this functionality.

My "hint" would be to get it working on one file first. That's
pretty easy. You can do it with a single Regexp. Then expand it to
a recursive directory search.

How do you want to detect binary files? By extension? Regexp can
probably help there too.

My "where to look advice" is the Regular Expression section (page 68)
for the conversion, the Find library (page 679) for the directory
traversal, and the OptionParser library (page 711) for the options
you want to give yourself.

I'm not knowledgeable about packaging Ruby .exe files, but I know
there are tools for this. Check out AllInOneRuby, for example.

If you really need this fast and coding it isn't a requirement, I'm
going to be blown away if a line ending conversion tool doesn't
already exist in some form.

Hope that helps.

James Edward Gray II
 
D

Daniel Berger

Elliott said:
Hello,

I'd like to recursively go through a bunch of directories and for text
file - convert any linefeed (LF) endings to carriage return line feeds
(CRLF).

For the end of line conversion, see File.nl_convert, part of the
"ptools" package.

Available on the RAA.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top