[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Filename Fix Help
- Subject: Re: Filename Fix Help
- From: nathan@cco.caltech.edu (Nathan Mates)
- Date: 19 Mar 1995 04:42:43 GMT
- Newsgroups: comp.sys.apple2
- Organization: California Institute of Technology, Pasadena
- References: <3kd701$4tv@lucy.infi.net>
In article <3kd701$4tv@lucy.infi.net>,
Dennis McClain-Furmanski <dynasor@infi.net> wrote:
>I've installed NAMEFIX in my system software, and so can accept nearly any
>file name that gets thrwon at me. But I still have problems with
>underscores. To download files I collect which have underscores in them, I
>have to go through and do a
>mv xxxxx_yyyy.zzz xxxxxyyyy.zzz
>for every file.
Ok, pretty trivial, assuming you have the language 'perl' installed
on your unix box. Here's a program I just wrote up to do just that.
Obviously, with a little work, it could be made to make all files fit
ProDOS 8 filename conventions...
--- Begin program. Cut here. Put in file 'nounder.prl'
#!/usr/local/bin/perl -w
# Converts all filenames with _'s in them to remove the _. Usage:
# nounder.prl *_*
# Make sure the user specified some files on the cmd line or give errors
@ARGV >= 1 ||
die "Usgae: nounder.prl *_*\n";
for ($i=0;$i<@ARGV;$i++) {
$_ = $ARGV[$i]; # put into working varb
s/_//g; # remove all _'s
if (-e $ARGV[$i]) { # make sure the specified file already exists
rename($ARGV[$i],$_) || die "Can't rename file $_";
}
}
--- End program. Cut here. Ouch!
The first line must contain the path to perl on your system, which
can be determined as follows:
# which perl
/usr/local/bin/perl
(Example from this system here. Two other systems I use a lot have
it in very different places). This should work with almost all versions
of Perl, but was only tested with version 4.0, pl36. Also, you'll have
to make the program runnable, the unix chmod command does that:
# chmod 755 nounder.prl
Basically, it first checks to make sure you specified some names,
or exits with an error message. Then, it goes through all the names
you specified (which is why calling it with 'nounder.prl *_*' is the
preferred way), rips any and all _'s out of the name, and renames the
file.
For example:
# ls
blah_2
# ~/progs/nounder.prl *_*
# ls
blah2
Have fun!
Nathan Mates
--
<*> Nathan Mates http://www.ugcs.caltech.edu/~nathan/ <*>
# "When you hear the voice of heaven, go out and start running. No
# matter how far away, set on a journey to be sure. ... No matter
# how far away, I'll be there to meet you." -- Silent Moebius #1