Jump to content

Simple file renaming script


Emeds
 Share

Recommended Posts

I'm wondering if anybody has made their own simple script to go through (recursively) sub-directories and remove x in filnames with y. I've looked online (python) and found some pretty long winded solutions, but I feel like this could be done simply in a nested for loop with only 1 or 2 modules.

 

for filename in dir:

    if filename contains ['list', 'of', 'items', 'easily', 'enumerated']

        newname = filename.replace(x,y)

        os.rename(filename,newname)

 

 

That is non recursive, but has been working for regular txt files for me, but not folders. Any suggestions?

Link to comment
Share on other sites

Nologic

For general files I use Flash Renamer but it's a retail app.

 

For renaming TV shows I use theRenamer.

 

For renaming Movies I use Media Center Master. I also use it to fetch metadata and images for both Movies & TV.

 

You can find a great list over at gizmo's freeware.

 

Plus don't forget to look for alternatives @ alternativeto

 

Oh for a light weight renaming...you could checkout the one included with FileMenu Tools. (Install the portable version, or risk getting hit by OpenCandy)

 

Past that I end up having to write custom AutoIt scripts to do really odd ball renaming.

 

If you really want to do something in python, I'd search on Stack Overflow...and if you don't find anything then post the question there.

Edited by Nologic
  • Like 1
Link to comment
Share on other sites

Ok, I'll probably head over to stack overflow if it will let me submit a question. And if I get a response, as well, I'll post the source code (probably a 40kb file). Thanks!

Link to comment
Share on other sites

Nologic

Well best of luck.

 

I'd be surprised if it came in at 40kb...I could do basic renaming in like 4-5kb in AutoIt.

 

If you are on Linux...you might try running some of those app's in Wine...theRenamer would likely fail as it's based on Flash...and well Flash on Linux sucks.

 

Course if you are on Linux you could try FileBot...not my first pick, but not bad at all, if you are doing media files (TV, Movie).

Link to comment
Share on other sites

JeremyG

Some powershell code.  This will do files AND folders.    You can just edit this text....change the strings to what you want....and paste it into your powershell Window. 

Make Sure You Set the $MediaFolder Correct!

 

 

If you want to save it for future use, save a .ps1 file.  Then you have to enable scripts to run (safety feature)  See this link: https://technet.microsoft.com/en-us/library/ee176961.aspx

$badstring = "StringIDontWant"
$goodstring = "StringIDoWant"
$MediaFolder = "X:\MyMediaFolder"

$files = Get-ChildItem $MediaFolder -Recurse
foreach ($item in $files)
{
	If ($item.Name.IndexOf($badstring) -ne -1)
	{
		$item | rename-Item -NewName { $_.name -replace $badstring, $goodstring }
	}
}

Edited by JeremyG
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Ah very cool JeremyG, I was trying out powershell recently. I did however complete a python script that does what I want after, if anyone else is interested. I have it setup to run like from the command line, and might even package it into a nice little executable tool with a UI.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...