It was thus said that the Great Toby Thain once stated:
On 15/12/11 10:09 PM, Toby Thain wrote:
On 15/12/11 9:44 PM, Mouse wrote:
[Please trim your quotes!]
But in any ahem Unix system, you can already do,
ad hoc:
$ ls | perl -n -e 'chomp;
m/(.*)\.log$/&& rename($_, "$1.old");'
I think using perl hardly counts as "any [] Unix system".
Or is that what your "ahem" is there for?
Also, that's going to misbehave, one way or another, on names
containing newlines, and possibly (I'm not entirely clear what "chomp"
does) names containing other characters.
I have a lot of files containing newlines, so yes, this is a serious
problem. What does DOS do with files containing newlines...
I mean file /names/ containing newlines. Of which I see a lot!
You guys want titanium screws where duct tape does just fine; and in the
heat of the moment I don't really want to have to write or pore over the
C code that would not have that issue. Cost/benefit. But if I *did* have
files with newlines, maybe Unix could handle that too. Who knows?
Do you mean a Unix program, or at the command line? A Unix program, yes
(two examples below). The command line? Um ... probably not with embedded
newlines in the filenames.
The C code isn't *that* bad, but really, any language on Unix that allows
you to interate over the entries in a directory will work and be a bit
easier than in C. In perl:
opendir(DIR,".");
while($file = readdir(DIR))
{
# handle file
print($file,"\n");
}
In Lua (not stock, granted, but with the right modules):
require "posix"
for file in posix.files(".") do
-- handle file
print(file) -- print adds "\n"
end
-spc