Home Pages of Oleksandr Nenko
Home page Softwarez Photo for all Savchenko 2016.10 Savchenko 2016.01 Mykolaiv 2015 Glade 15° Private photos Turkey 2020 Egypt 2015 Egypt 2012 Egypt 2011 Galina Alina Nenko Vova Nenko Home: [EN] [UK] [RU] Contact me: nenko@nenko.net |
Scripting in Python for WindowsHaving a private project, which required the handling of thousands of photo/image files, I was stuck with 2 problems:
So I have batch script directory C:\SRV, included in PATH, with several very simple BAT files, like: set PYTHONPATH=C:\Prjs\nanolib;%PYTHONPATH% py -m nano_file_utils.filename_processing %*which calls Python script in C:\Prjs\nanolib\nano_file_utils\filename_processing.py For Python specific details go to github, here are just top level explanation of 3 commands I created and used for my purposes. NF4PO - Numberize Filenames 4or Proper OrderingHas no arguments, processes files in current directory. Detects common pattern of several file names, with numeric field, updates this numeric field by left padding with zeros, so all file names has equal length and proper ordering. Example:
renamer - goes through the files in a directory and renames files according to the Python written logicThis command requires Python programming. It has single argument - extension of files to be renamed, w/o dot. How to use it:
def new_name(old): file_base_name, file_extension = os.path.splitext(old) # prefix = file_base_name[:1] prefix = file_base_name[6:] return prefix + file_extensionThis command renames only one type of files during one run, for example, RENAMER JPG renames only JPG files. ren-lambda - goes through the files in a directory, filter and renames files according to the given Python lambdasThe script works in the current directory, it accepts 2 command line arguments:
new-name-expression returns string as new name, constructed from 'base' and 'ext' YES, there is some mess with the term 'argument'. MS DOS Command REN-LAMBDA.BAT accepts 2 command line arguments, each of this argument is lambda expression, which takes 2 lambda arguments. Actually the reality is even more complicated, because both lambda expressions get not 2 but 6 arguments: base, ext, Base, Ext, BASE, EXT which correspond to lower case, original and upper case variations of filename. Example: For all files with extension .png or .PNG or .pNg set the extension to .JPGren-lambda "ext == '.png'" "Base + '.JPG'"Hollow filter and action: ren-lambda "1==2" "Base + Ext"Example of useful filter: ren-lambda "Base.startswith('IMG')" "Base + Ext" |
||||
Terms and Conditions (c) 2005, 2006, 2008, 2009, 2011, 2012, ..., 2023 NAN |