glob

glob finds the same file 10 times

glob finds the same file 10 times Question: Why does the recursive=True lead to finding the same file 10 times. >>> for g in glob.glob("/home/result/test/**/**/**/*.xml", recursive=True): … if "testsystems" in g: … print(f"{g}") … /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml /home/result/test/foo/bar/test_results/testsystems.xml According to the docs I expected to need to use recursive=True …

Total answers: 1

Selecting multiple files according to timestamp with glob

Selecting multiple files according to timestamp with glob Question: I have a directory with 7000 daily .tif files, spanning from 2002 to 2022. Each file has a respective indication of its timestamp, in the yyyy/mm/dd format, as: My_file_20020513.tif I’m trying to select the file paths according to their respective month, i.e. all files from January, …

Total answers: 1

Wrong snakemake glob_wilcards and wildcard_constraints

Wrong snakemake glob_wilcards and wildcard_constraints Question: Within my snakemake pipeline I’m trying to retrieve the correct wildcards. I’ve looked into wildcard_constraints and this post and this post, however I can’t figure out the exact solution. Here’s an example of file names within 2 datasets. 1 dataset contains paired mouse RNAseq read files and another dataset …

Total answers: 2

How to read csv files based on multiple index_col argument?

How to read csv files based on multiple index_col argument? Question: I have a problem which might be easy for majority of people here. I have four folders: SA1, SA2, SA3, SA4. Each folder has around 60 csv files. I have defined the path like this: my_string = "{0}/folder1/{1}/{1} something/{2}/AUST" analytics_path = "C:/Users/…../SharePoint – Documents/folder2" …

Total answers: 1

How to work with regex in Pathlib correctly?

How to work with regex in Pathlib correctly? Question: I want find all images and trying to use pathlib, but my reg expression don’t work. where I went wrong? from pathlib import Path FILE_PATHS=list(Path(‘./photos/test’).rglob(‘*.(jpe?g|png)’)) print(len(FILE_PATHS)) FILE_PATHS=list(Path(‘./photos/test’).rglob(‘*.jpg’))#11104 print(len(FILE_PATHS)) 0 11104 Asked By: Piter || Source Answers: Get list of files using Regex import re p = …

Total answers: 2

Search multiple patterns using glob only once

Search multiple patterns using glob only once Question: I want to use glob function in order to find files located in folders corresponding to two different type of folder names. The solution I found would be simply: import glob files1 = glob.glob(‘*type1*/*’) files2 = glob.glob(‘*type2*/*’) files = files1 + files2 Is there any way of …

Total answers: 2

Extract only certain files from a folder in python as list

Extract only certain files from a folder in python as list Question: I have the following list of files in my folder: data.txt an_123.txt info.log an_234.txt filename.txt main.py an_55.txt I would like to extract only the .txt files that have prefix an as list. The output should look like the following: [an_123.txt, an_234.txt, an_55.txt] What …

Total answers: 2

What does the star * have to do with the glob in python?

How does the star * behave in Python's regex vs. glob pattern search? Question: I am trying to understand how glob works, also how is the star * related to glob and how it works vs. how it works in regex? For example, I know glob.glob("C:UsersMeMyFolder*.txt") would match and return any files with the extension …

Total answers: 1

What's the fastest way to recursively search for files in python?

What's the fastest way to recursively search for files in python? Question: I need to generate a list of files with paths that contain a certain string by recursively searching. I’m doing this currently like this: for i in iglob(starting_directory+’/**/*’, recursive=True): if filemask in i.split(‘\’)[-1]: # ignore directories that contain the filemask filelist.append(i) This works, …

Total answers: 2

Python glob include hidden files and folders

Python glob include hidden files and folders Question: I try to loop over all files matching a certain extension, including those inside hidden folders. So far I haven’t found a way to do this with iglob. This works for all folder except those starting with a dot: import glob for filename in glob.iglob(‘/path/**/*.ext’, recursive=True): print(filename) …

Total answers: 4