Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to remove spaces from filenames' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to remove spaces from filenames
Authored by: maintain1 on Mar 10, '08 05:15:10PM

#!/usr/bin/perl -w

# mvSpace.pl
# WARNING
## This will overwrite files if they have the same name
## So say we have file 1, f ile1, file 1
# After the script we will have one folder called folder1
#
# Created by mar8 on 3/10/08.
#
# the chdir command should change to a users home directory
chdir;
# you could enter the full path name to the folder
$workingDir = "\./Documents/spacefolder/";
opendir DH, "$workingDir" or die ;
my @workingFiles;
my $workingFiles_r = \@workingFiles;
while ($_ = readdir(DH)) {

next if $_ eq "." or $_ eq ".." ;
push @{workingFiles_r}, $_;
}
closedir DH;
foreach (@{workingFiles_r}) {


my $input = "$workingDir$_";
#print "my input is equal to ", $input,"\n";
s/\ //g;
my $output = "$workingDir$_";
#print "my output is equal to ", $output,"\n";

if ("$input" ne "$output") {
rename "$input", "$output" or warn "Can't move file: $!";
}
}



[ Reply to This | # ]
A script to remove spaces from filenames
Authored by: degiy on Aug 13, '10 03:06:00AM

>out;ls -1 | grep ' ' | tr ' ' '!' | while read a ; do b=`echo $a | tr '!' '_'`; echo "mv ,$a, $b" ;done | tr , \' | tr ! ' ' > out ; . ./out; \rm -f out



[ Reply to This | # ]