Created
September 2, 2014 18:36
-
-
Save jdblischak/c9b77b4838c9d5b7b3da to your computer and use it in GitHub Desktop.
Quick example of renaming files in nested directory structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Renames all files using name of directory. | |
# e.g. sample_name_1/s_1_sequence.txt.gz -> sample_name_1_s_1_sequence.txt.gz | |
import glob | |
import shutil | |
filepaths = glob.glob("sample_name_*/s_*_sequence.txt.gz") | |
new_names = [x.replace("/", "_") for x in filepaths] | |
[shutil.copyfile(x[0], x[1]) for x in zip(filepaths, new_names)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set up a directory with files in the following format: | |
# | |
# - s_1_sequence.txt.gz | |
# - sample_name_1 -- | |
# - s_2_sequence.txt.gz | |
# | |
# -- | |
# | |
# - s_1_sequence.txt.gz | |
# - sample_name_2 -- | |
# - s_2_sequence.txt.gz | |
# | |
mkdir sample_name_{1..9} | |
for dir in sample_name_* | |
do | |
touch $dir/s_{1..3}_sequence.txt.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment