Executes your command for each file selected using glob expression(s).
Project description
para-cada
Para cada in Spanish means For each. The tool executes your command for each file selected using glob expression(s).
Why? Let's say you have multiple .tgz
archives and you would like to extract them in one shot. In bash you can do:
ls *.tgz | xargs -IT tar xzvf T
or alternatively:
for T in *.tgz; do tar xzvf $T; done
Both options are relatively complex. This is where cada can help. Simply do:
cada 'tar xzvf *.tgz'
Cada knows where glob expression is. It executes entire command with subsequent values corresponding to this expression. Additionally, user may transform those values using regular Python syntax. Take a look at the examples below and the tutorial.
Installation
pip install para-cada
Examples
It is recommended to run examples below in the dry mode, by adding -d
flag. This way you will only simulate what would happen without actually applying any changes to the filesystem.
# backup all the `.txt` files in the current directory
cada 'cp *.txt {}.bkp'
# restore backups above
cada 'mv *.bkp {}' 'p.stem'
# rename .txt files so that the names look like titles
# and extensions are in lower case
cada 'mv *.txt {}' 'Path(s0.title()).with_suffix(p0.suffix.lower())'
# replace 'config' by 'conf' in the names of the files in current dir
cada 'mv * {}' 's.replace("config", "conf")'
# prepend each text file with subsequent numbers, 0-padded
cada 'mv *.txt {i:04d}_{}'
# to each text file add a suffix that represents MD5 sum calculated over the file content
cada 'mv *.txt {s}.{e}' 'hashlib.md5(p.read_bytes()).hexdigest()' -i hashlib
# put your images in subdirectories according to their creation date
cada 'mkdir -p {e} && mv *.jpg {e}' \
'fromtimestamp(getctime(s)).strftime("%Y-%m-%d")' \
-i os.path.getctime -i datetime.datetime.fromtimestamp
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for para_cada-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c99b3667a97c1dd6fa4554b8cf7db975231b453d1ee3c34b01f7604f43457f0b |
|
MD5 | d0eeb86978696b38b1ca93a435946eba |
|
BLAKE2b-256 | d781347e08b2cebeb02f0bfafc40181c08b8403f8e9583be68b70243dfda119a |