Jump to content

Extension to Lowercase to Fix EPACK32


Recommended Posts

  • Premium

Yo guys,

here you have a script that i made to fix the annoying fact that epack32 craps out when you use for some reason uppercase extensions, this can happen with gr2's for example.

Here you have a video showing how to use it properly, this is for an earlier version but you should get how it works.

I'm also writing a py library that acts as manager for the query/msm/protos etc, the quality of the code is been improving since this script, stay tuned for the future.

 

## Author North - Fleon
# Usage: python scriptname.py

import os,fnmatch,shutil,re

lenght = 3 # Set here the size of the extension, default 3
extension = None;

class FileManager():
    @staticmethod
    def Main():
        print("\n\n#### Extension to lowercase V.01 ####\n\n")
        print("Renames recursively from a caps extension to lower.")
        print("USAGE: Place your content and script into C:\workdir")
        print("The script will recursively change the extension to lower.")
        input(">>>> Press ENTER to continue...")
        # In case you are using a python version that is equal or lower than 2.7 please use raw_input instead of input above.
        FileManager.GetExtension()
        FileManager.GetLogFile()
        FileManager.RenameFile()
       
    def GetExtension():
        global extension
        global lenght
        while not extension or len(extension) > lenght:
            print("Tell me wich extension would you like to lower")
            print("/!\ The extension must not be left empty.")
            extension = str(input(">>>> Now type an extension: (Example: txt) \n"))
        return(extension)
   
   
    def GetLogFile():
        path = os.getcwd()
        global extension
        Extension = "*." + str(extension)
        with open("rename_log", "w") as File_txt:
            for root, dirnames, filenames in os.walk(path):
                for gr2 in fnmatch.filter(filenames, Extension):
                    write_txt = (os.path.join(root, gr2) +"\n")
                    File_txt.write(write_txt)
                   
    def RenameFile():
        global extension
        with open("rename_log", "r") as file_directory:
            for element in file_directory:
                element = element[:-1]
                ren_element = element.replace(str.upper(extension), str.lower(extension))
                os.rename(element, ren_element)
                print(">>>> This file has been renamed: " + element)       
        total_elements = sum(1 for line in open('rename_log'))   
        print("Total renamed files: {0}".format(str(total_elements)))

FileManager.Main()

 

  • Love 2
Link to comment
Share on other sites

First one, thanks for release.
Here are some tips wich you can use on future.

total_elements = sum(1 for line in open('rename_log'))
  • total_elements = len(open('rename_log').readlines())
element.replace(str.upper(extension), str.lower(extension))
  • element.replace(extension.upper(), extension.lower())
print("Total renamed files: {0}".format(str(total_elements)))
  • That's totally a bit unfriendly, the str.format() detected automatically the data type of argument, you don't have to convert it as string.
  • Also you don't need to enumerate your arguments as {0} {1} etc, you can do that only if you have more arguments and you get stuck.
  • Should look like:
  •         print("Total renamed files: {}".format(total_elements))
return(extension)

Why you return something (outside of loop) if you don't use the result?

        global extension
        global lenght

Why you use global variables when you can declare them inside of your class FileManager?

class FileManager:
    def __init__(self):
        self.length = 3 # Set here the size of the extension, default 3.
        self.extension = str()

	def Main(self):
		pass
	def GetExtension(self):
		pass
	def GetLogFile(self):
		pass
	def RenameFile(self):
		pass
		
Instance = FileManager()
Instance.Main()

 

Good luck on future and i hope you will use these small tips.

  • Love 3
Link to comment
Share on other sites

  • Premium

Thanks for the tips your suggestion are welcome, this was a bit ago and the overall knownledge is going up with the time.

And sorry for the few weird things in the code aswell, it was structured differently at the beginning (video) and i kinda fast-review it a couple of months ago.

Will edit the snippet with your suggestions asap (2 stoned atm)

  • Love 2
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.