General discussion

Locked

Ranaming of files

By mayuresh ·
Hi Ppl

I like all my filenames to be in samll case.
However it becomes quite a pain to sit and rename all the new files I get from outside.
Can i write a script/bat etc to automate the process.

TIA

Mayuresh

This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Ranaming of files

by TheChas In reply to Ranaming of files

This won't take care of everything.
Depending on your OS and IE version, there is a checkbox in the file view settings that can be unchecked to prevent all uppercase file names.

I believe that it will still allow the first letter to be uppercase.

Collapse -

Ranaming of files

by mayuresh In reply to Ranaming of files

Poster rated this answer

Collapse -

Ranaming of files

by TimTheToolMan In reply to Ranaming of files

Hi,

Yep. You will need to install perl on your machine, but here is a link to a site containing the script you want and a description. All you need to to is cut and paste!

http://blazonry.com/perl/recurse.php

(remove spaces from the above URL)

Oh, and if you dont have perl yet, its freely downloadable from

http://www.perl.com/

Hope this helps,
Cheers,
Tim.

Collapse -

Ranaming of files

by TimTheToolMan In reply to Ranaming of files

...but because I could I went one further...

Once you've installed perl, cut and paste this code into a txt document using notepad, rename it to have a .bat extension rather than .txt and stick it on your desktop.

Now you'll be able to simply drag and drop folders from the windows explorer onto the icon and it will automatically rename the folder's contents recursively - ie. all its subfolders too...

@rem = '--*-Perl-*--
@echo off

if not exist %0 set batchf=%0.bat
if exist %0 set batchf=%0

if "%OS%" == "Windows_NT" goto WinNT
perl -x %batchf% %1 %2 %3 %4 %5 %6 %7 %8 %9
if not errorlevel 0 goto fail1
goto endofperl

:WinNT
perl -x %batchf% %*
if not errorlevel 0 goto fail1
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul

:endofperl
echo.
pause
exit

:fail1
echo.
echo Problem with the rename script.
echo.
goto endofperl

#!perl

#use File::Recurse;
use File::Find;

# read in directory
@ARGV = qw(.) unless @ARGV;

# verify directory
if (-d @ARGV[0])
{
print "Working Directory: @ARGV[0]\n";
}
else
{
print "\nError: Directory Not Found @ARGV[0]\n"; exit(0);
}


# call recurse function from module
# this applies the sub-routine lcName to all files
# in the specified directory
find(\&lcName, @ARGV);


# define the lcName sub-routine which lowercases all files


sub lcName {
# receive passed filename
$filename = $File::Find::name;

$newfilename = $filename;

# regexp that converts to lowercase
$newfilename =~ tr/A-Z/a-z/;

# if I can read and write to it
# rename the filename tothe lowercase one
if ((-r $filename) && (-w $filename)) {
rename($filename, $newfilename);
print " Renamed: $filename to $newfilename\n";
}
}

Cheers,
Tim.

Collapse -

Ranaming of files

by TimTheToolMan In reply to Ranaming of files

...and one last thing.

Windows isn't generally case sensitive, but Java is. Dont use this to rename .java filenames or you'll find they may not work anymore.

Also...all the formatting has been lost with the post, but it shouldn't matter... youcan re-indent it if you like.

Cheers,
Tim.

Collapse -

Ranaming of files

by mayuresh In reply to Ranaming of files

Thanks guys. I will be trying it at home. Will post on how it works out.

Thanks again..

Mayuresh

Collapse -

Ranaming of files

by mayuresh In reply to Ranaming of files

Tim...the perl solution was amazing.
It works like a charm.
I went one step futher though. Instead of keeping it on my desktop, which was kinda difficult to drop any folder on it. So i just added my bat to the "send to" option in my right click.
Thanks Again.

Mayuresh

ps: if you'll just reply, i can give you all the points u so deserve. I still can't get the hang of how to properly asign points..comments etc...oh well..maybe some day :-)

Collapse -

Ranaming of files

by TimTheToolMan In reply to Ranaming of files

Hi Mayuresh,

I'm glad the script worked so well for you. Adding it to the send-to menu was a great idea...nice touch!

Cheers,
Tim.

Collapse -

Ranaming of files

by mayuresh In reply to Ranaming of files

Thanks Dude.

You throughly deserve these points.

See Ya around.

mayuresh

Collapse -

Ranaming of files

by mayuresh In reply to Ranaming of files

This question was closed by the author

Back to Windows Forum
10 total posts (Page 1 of 1)  

Related Discussions

Related Forums