Compare commits
4 Commits
682503a24a
...
34e5b107ff
Author | SHA1 | Date | |
---|---|---|---|
34e5b107ff | |||
70af81ed84 | |||
b745915e49 | |||
c6d79c9eb1 |
10
README.md
10
README.md
@ -31,4 +31,12 @@ This program makes heavy use of REGEX, also known as Regular Expression to give
|
||||
|
||||
Let's say we have files `run325-a-1.vcf`, `run326-b-2.vcf`, and `run327-b-3.vcf`. If we know that all that matters is the `1` after the `run[numbers]-[character]-`, we can write `run\d+-\w-(\d).vcf` which will match with all 3 of the above examples, and select the last digit. The program can then use a given CSV to look up the selected digits and replace the name with what is given by the CSV.
|
||||
|
||||
For learning and testing your own REGEX, checkout [regex101.com](https://regex101.com/), which allows you to write the strings that you're trying to match, and the REGEX. It will show you live which parts of the strings match to what, if any parts match.
|
||||
For learning and testing your own REGEX, checkout [regex101.com](https://regex101.com/), which allows you to write the strings that you're trying to match, and the REGEX. It will show you live which parts of the strings match to what, if any parts match.
|
||||
|
||||
## Not Working?
|
||||
|
||||
If the program is not working the way you would like it, try running the program in `-v DEBUG` mode which increases verbosity. Typically, files not being renamed can be attributed to one of two problems:
|
||||
|
||||
1. It's looking in the wrong directory. The solution would be to double check that the directory it's looking in (printed by the program each run) is correct. If not, try adding quotes around the path in the command line.
|
||||
|
||||
2. The provided REGEX pattern isn't matching to any of the files. In this case, test one or two of the files at [regex101.com](https://regex101.com/) with your pattern.
|
@ -7,7 +7,7 @@ from renamebycsv.renamer import find_all_candidates, rename_by_csv
|
||||
|
||||
|
||||
def run(args):
|
||||
candidates = find_all_candidates(args.input_dir, args.regex, args.recursive)
|
||||
candidates = find_all_candidates(args.input_dir, args.pattern, args.recursive)
|
||||
rename_by_csv(
|
||||
args.csv,
|
||||
candidates,
|
||||
|
@ -6,6 +6,12 @@ from typing import Iterable
|
||||
|
||||
|
||||
def find_all_candidates(input_dir: str, regex: str, recursive: bool):
|
||||
logging.info(
|
||||
'Searching "%s" for files that match "%s" %s',
|
||||
input_dir,
|
||||
regex,
|
||||
"recursively" if recursive else "non-recursively",
|
||||
)
|
||||
results = []
|
||||
for subitem in os.listdir(input_dir):
|
||||
subitem_path = os.path.join(input_dir, subitem)
|
||||
@ -19,6 +25,13 @@ def find_all_candidates(input_dir: str, regex: str, recursive: bool):
|
||||
continue
|
||||
results.append((subitem_path, subitem, match))
|
||||
logging.debug(f'Collecting "{subitem}"...')
|
||||
if len(results) < 1:
|
||||
logging.info(
|
||||
'No results found matching "%s" in "%s". Please double check your REGEX '
|
||||
"pattern and directory being searched.",
|
||||
regex,
|
||||
input_dir,
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user