IOS project renamed

 Difficulties encountered: Do a lot of small projects, think that many basic things are basically the same, but they cannot be encapsulated, and some configurations need to be modified, such as project Info. Baidu has changed the name of the project, the process is too complicated for me... For example, this buddy's modification method link 

Then when I created a new private library today, I suddenly found that CocoaPods ' Pod Lib Create
The principle is to download the template and then replace the content

emmm ...

The idea came to directly create a new project with the same basic configuration, and then replace the project name...

Life is too short to start working with python that I just learned for two days

an hour of code

import them


def deal_file_content(file_path, old_name, new_name): # deal with the replaced file
    try:
        if file_path.endswith('.DS_Store'):
            return
        f = open(file_path, 'r+', )
        content = f.readlines()
        f.seek(0, 0)
        for line in content:
            line_new = line.replace(old_name, new_name)
            f.write(line_new)
        f.close()
    except Exception as err:
        print(file_path)
        print(err)


# Traverse all subdirectories in the specified directory and modify
def each_file(dir_path, old_name, new_name):
    path_dir = os.listdir(dir_path)
    for allDir in path_dir:
        # I choose to ignore a few folders. I don't handle it well. I have enough for you. Look at the changes.
        if allDir == 'Assets.xcassets' or allDir == 'base_project' or allDir == 'Base.lproj':
            continue
        child = os.path.join('%s/%s' % (dir_path, allDir))
        if allDir.__contains__(old_name):
            if os.path.isdir(child): # is a folder
                new_path = os.path.join('%s/%s' % (dir_path, allDir.replace(old_name, new_name)))
                os.rename(child, new_path)
                child = new_path
        if os.path.isdir(child):
            each_file(child, old_name, new_name)
        else:
            deal_file_content(child, old_name, new_name)

 

# call to execute

each_file('/Users/jihaifeng/Desktop/TestFrame/BaseOCWorkspace/Farming', old_name="Farming", new_name="SearchEverything")

 Just love the simple and rude solution!!!











 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325757020&siteId=291194637