Giter Site home page Giter Site logo

py-filename's Introduction

py-filename

A Python script to add/remove file name prefix/suffix

Core functions: filename.py

  1. filename.searchByExt(rootpath, ext) Find files in rootpath with a certain file extentison of ext, obtain their file paths, store those file paths into a list, and return it.

  2. filename.modifyPrefix(filelist, oldPrefix='', newPrefix='') For the files listed in filelist, change their file name prefix from oldPrefix to newPrefix.

  3. filename.modifySuffix(filelist, oldSuffix='', newSuffix='') For the files listed in filelist, change their file name suffix from oldSuffix to newSuffix.

Sample code: filename_sample_code.py

# -*- coding: utf-8 -*-

import filename

def main():
    rootpath = '~/Documents' # change this to a proper directory path
    ext = 'pdf' # change it to whatever file extension you need
    oldPrefix = '' # left empty when adding new prefix
    newPrefix = 'prefix-' # left empty when removing old prefix
    oldSuffix = '' # left empty when adding new suffix
    newSuffix = '-suffix' # left empty when removing old suffix

    results = filename.searchByExt(rootpath, ext)
    filename.modifyPrefix(results, oldPrefix, newPrefix)
    filename.modifySuffix(results, oldSuffix, newSuffix)

if __name__ == '__main__':
    main()

Further reading

  1. Python和正则表达式:给PDF文件批量添加前缀或后缀

py-filename's People

Contributors

irockbunny avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

py-filename's Issues

Add code

Add myfile.py and sample code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.