[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: shell scripts and spaces in file/folder names



On Thu, Apr 17, 2003 at 05:47:45PM -0500, Ron Johnson wrote:
> However, you should learn perl or python.  I really like python, but
> perl is ubiquitous...
> 
> Here's a script I use to change files with spaces to dashes.

Here's what i use:

#!/usr/bin/perl
## rename files, straight from the Perl Cookbook

my $op = shift or die "Usage: $0 expr [files]\n";
chomp(@ARGV=<STDIN>) unless @ARGV;
for (@ARGV) {
	my $was= $_;
	eval $op;
	die $@ if $@;
	rename($was,$_) unless $was eq $_;
}

__END__

usage:
ren.pl "s/ /-/g" files

quicker and less error prone than one-liners.

-troy



Reply to: