if you ever need to rename 100+ files...

I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy). ----- begin script----- import os for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname) ----- end script------ It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.

Thanks for script, Is it OS specific? Are there pre-requisites? Install python etc? Thanks James On Sat, Nov 21, 2009 at 10:20 AM, saidimu apale <saidimu@gmail.com> wrote:
I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy).
----- begin script----- import os
for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname)
----- end script------
It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
-- Best Regards James Wachira Nairobi .ke | twitter: jwaciira | yahoo: jwaciira | gtalk: jwaciira

Python is cross-platform and the script doesn't use any platform-specific code so it should work on all platforms. Behind the scenes python does the heavy lifting to translate the script to platform-specific code. If you're on Windows you should be able to launch the python interpreter by clicking on whatever shortcut it provides. From the interpreter you can type the script (one per line), but you don't need to save it in a file (though nothing is stopping you from doing so). I hope that helps. saidi On Sat, Nov 21, 2009 at 3:41 AM, James Wachira <jwaciira.lists@gmail.com>wrote:
Thanks for script, Is it OS specific? Are there pre-requisites? Install python etc? Thanks James
On Sat, Nov 21, 2009 at 10:20 AM, saidimu apale <saidimu@gmail.com> wrote:
I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy).
----- begin script----- import os
for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname)
----- end script------
It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
-- Best Regards James Wachira Nairobi .ke | twitter: jwaciira | yahoo: jwaciira | gtalk: jwaciira
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general

If you're in Linux, use: # rename 'y/\ /_/' * ________________________________ From: saidimu apale <saidimu@gmail.com> To: Skunkworks forum <skunkworks@lists.my.co.ke> Sent: Sat, November 21, 2009 2:20:49 AM Subject: [Skunkworks] if you ever need to rename 100+ files... I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy). ----- begin script----- import os for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname) ----- end script------ It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.

if on windows, there is a nifty tool called Total Commander, that has a multi-rename facility, amoing many other uses. 2009/11/21 Bernard Owuor <b_owuor@yahoo.com>
If you're in Linux, use:
# rename 'y/\ /_/' *
------------------------------ *From:* saidimu apale <saidimu@gmail.com> *To:* Skunkworks forum <skunkworks@lists.my.co.ke> *Sent:* Sat, November 21, 2009 2:20:49 AM *Subject:* [Skunkworks] if you ever need to rename 100+ files...
I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy).
----- begin script----- import os
for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname)
----- end script------
It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general

For those on Windows: http://www.1-4a.com/rename/ On Sat, Nov 21, 2009 at 8:26 PM, Njoroge Tito <titonjoroge@gmail.com> wrote:
if on windows, there is a nifty tool called Total Commander, that has a multi-rename facility, amoing many other uses.
2009/11/21 Bernard Owuor <b_owuor@yahoo.com>
If you're in Linux, use:
# rename 'y/\ /_/' *
________________________________ From: saidimu apale <saidimu@gmail.com> To: Skunkworks forum <skunkworks@lists.my.co.ke> Sent: Sat, November 21, 2009 2:20:49 AM Subject: [Skunkworks] if you ever need to rename 100+ files...
I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy). ----- begin script----- import os for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname) ----- end script------ It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
-- Regards, Brian Ngure

The best ever I have found (for Windows). It's free, it's fast and It's really a killer; a must-have app !! www.bulkrenameutility.co.uk TheBigBoss On Mon, Nov 23, 2009 at 10:50 AM, Brian Ngure <brian@mystique.boldlygoingnowhere.org> wrote:
For those on Windows: http://www.1-4a.com/rename/
On Sat, Nov 21, 2009 at 8:26 PM, Njoroge Tito <titonjoroge@gmail.com> wrote:
if on windows, there is a nifty tool called Total Commander, that has a multi-rename facility, amoing many other uses.
2009/11/21 Bernard Owuor <b_owuor@yahoo.com>
If you're in Linux, use:
# rename 'y/\ /_/' *
________________________________ From: saidimu apale <saidimu@gmail.com> To: Skunkworks forum <skunkworks@lists.my.co.ke> Sent: Sat, November 21, 2009 2:20:49 AM Subject: [Skunkworks] if you ever need to rename 100+ files...
I needed to quickly and painlessly rename some files by replacing spaces with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy). ----- begin script----- import os for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname) ----- end script------ It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
-- Regards,
Brian Ngure _______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general

Thunar file manager has a bulk rename facility (Linux) On Mon, Nov 23, 2009 at 11:08, TheBigBoss <thebigboss@peperuka.com> wrote:
The best ever I have found (for Windows). It's free, it's fast and It's really a killer; a must-have app !!
www.bulkrenameutility.co.uk
TheBigBoss
On Mon, Nov 23, 2009 at 10:50 AM, Brian Ngure <brian@mystique.boldlygoingnowhere.org> wrote:
For those on Windows: http://www.1-4a.com/rename/
On Sat, Nov 21, 2009 at 8:26 PM, Njoroge Tito <titonjoroge@gmail.com> wrote:
if on windows, there is a nifty tool called Total Commander, that has a multi-rename facility, amoing many other uses.
2009/11/21 Bernard Owuor <b_owuor@yahoo.com>
If you're in Linux, use:
# rename 'y/\ /_/' *
________________________________ From: saidimu apale <saidimu@gmail.com> To: Skunkworks forum <skunkworks@lists.my.co.ke> Sent: Sat, November 21, 2009 2:20:49 AM Subject: [Skunkworks] if you ever need to rename 100+ files...
I needed to quickly and painlessly rename some files by replacing
spaces
with underscores (_). Here's a quick and dirty python script that did it for me. I ran it from the python interpreter command-line (I didn't save the script to a file... lazy). ----- begin script----- import os for file in os.listdir(os.getcwd()): newname = "_".join(file.split()) os.rename(file, newname) ----- end script------ It's a quick and dirty script so there's no error-handling of *any* sort. But that's trivial to add if you needed it.
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
-- Regards,
Brian Ngure _______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke Other lists ------------- Announce: http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks-announce Science: http://lists.my.co.ke/cgi-bin/mailman/listinfo/science kazi: http://lists.my.co.ke/cgi-bin/mailman/admin/kazi/general
participants (7)
-
Arthur Buliva
-
Bernard Owuor
-
Brian Ngure
-
James Wachira
-
Njoroge Tito
-
saidimu apale
-
TheBigBoss