Questions tagged [fnmatch]

`fnmatch` is the name for both a C-language standard library function for performing shell-style wildcard pattern-matching against strings, and one of many wrapper implementations exposing the mechanism of C-language `fnmatch` to a higher-level language – i.e. Python, Ruby, `awk`, &c.

fnmatch is both:

  1. A -language standard library function, fnmatch(…), and
  2. Any one of a number of many wrapper implementations exposing the mechanism of -language fnmatch to a higher-level language

One of the most noteworthy users of fnmatch(…) is – specifically, patterns defined in files are applied using fnmatch(…) – q.v. the [documentation]4 and the [source code]5 itself.

Questions about pattern-matching can often interchangeably refer to fnmatch patterns as well.

The full signature of the fnmatch(…) C function is:

int fnmatch(char const* pattern,
            char const* string,
                    int flags);

For details of its use, see the man page for fnmatch(3).

60 questions
0
votes
1 answer

TFS - msbuild - fnmatch where filename doesn't contain character

I'm setting up a build in TFS. In the MSBuild step, it allows wildcards for the project name (like **/*.csproj). I'm assuming that it accepts fnmatch syntax like other fields in TFS. I want to build all projects that don't contain the number "6" in…
JED
  • 1,538
  • 2
  • 19
  • 47
0
votes
2 answers

Read csv files from a folder based on condition in Python

I want to read csv files from a folder based on condition. I just want to read csv files that include “1441” in the filename. I used fnmatch, but it doesn’t work. Can anyone help? path_to_parent = r"C:\Users\Desktop\books/chapter_1" for csv_file in…
0
votes
1 answer

How to loop list in fnmatch

I am trying to move files from current directory to directory named 'python' in current directory if they are found in a list called 'file'. With the result that the file named '1245' will remain in same directory. I am trying to use fnmatch to…
0
votes
2 answers

python: check if a specific string is part of a filename

I have a list, where each entry consists of 5 individual random numbers: List-output: ... ['00349'] ['02300'] ['00020'] ... Now I have two nested for loops. The outer loop iterates over this list. The inner loop iterates over a buch of files which…
Hugh Rivers
  • 5
  • 1
  • 4
0
votes
1 answer

blacklist href in python to remove junk sites

I want it to print every site that isnt blacklisted(how the code looks so far) but it doesnt work if you change the string in the last if statement from pass to print(site) then it prints everything in the black list, yet it wont print everything…
00xZ
  • 1
  • 2
0
votes
1 answer

Trying to pass files from a subfolder to a new folder after Filtering

I am trying to make a code that allows me to copy files from various subfolders to a new folder. The main problem and why it wasn't a straight forward thing to deal with since the beginning is that all the files start the same and end the same, just…
AndSS
  • 11
  • 1
0
votes
1 answer

DataDog - pass multiple fnmatch paterns to configuration

init_config: instances: - directory: /mnt/ftp/generic/Salesorder pattern: '*_12_*.csv' filegauges: true dirtagname: history - directory: /mnt/ftp/generic/Salesorder pattern: '2021_*_*.csv' filegauges: true dirtagname:…
Stevan Tosic
  • 6,561
  • 10
  • 55
  • 110
0
votes
1 answer

DataDog Directory file matching pattern fails to match any files

The directory contains more than 20 files. As explained in the DataDog directory documentation, a maximum of 20 files can be tracked. So I tried to configure the data dog directory configuration init_config: instances: - directory:…
Stevan Tosic
  • 6,561
  • 10
  • 55
  • 110
0
votes
1 answer

How to suppress unnecessary output produced by fnmatch in Python?

I want to check is a file with a specific name exists or not in a directory. The directory contains 3 files: 20210401.NYSE.csv 20210402.NYSE.csv 20210403.NYSE.csv The code that I'm using: import sys, os, re, fnmatch input_dir =…
kamokoba
  • 497
  • 9
  • 17
0
votes
1 answer

fnmatch.fnmatch use a pattern to exclude sub directories

I have a directory structure like this rootFolder/ - some.jar - another.jar subDirectory/ -some1.jar I only want to get the files in the rootFolder and not the subDirectory (some.jar and another.jar). I have also tried…
Syed Osama Maruf
  • 1,895
  • 2
  • 20
  • 37
0
votes
2 answers

Python 2.7 fnmatch NOT editing text

I have a file with 600k+ records of string labels I am trying to edit with an update cursor using both the string modules and fnmatch to find patterns to edit. The section using fnmatch is successfully printing the matched records but not changing /…
0
votes
1 answer

Python: Display all options of a Unix wildcarded string with square brackets (reverse glob/fnmatch)

I have a large dataset with rows of wildcarded strings e.g. 8145[012] 8146[01234] 8147[0134567] I would like an efficient way to expand these out into unique rows for each combination, e.g. 81450 81451 81452 81460 81461 81462 etc... What is the…
0
votes
1 answer

Problems with my first project of renaming file names

I recently started with python since I want to become better in geophysics and processing data. I began with a little sideproject to rename the monthly extract files of my bank account. They have a silly order of date and name and I just want to…
janicans
  • 11
  • 2
0
votes
1 answer

How to use fnmatch to check pattern at specific position of string?

I have a folder (call it F) with subfolders with names formatted as yyyy.doy (example 2020.001 for January first 2020). in each of the sub folders are file for multiple instruments. each file designates which instrument it is for in the 16th, 17th,…
0
votes
1 answer

Slow file trawler -- python

I've written a short script searches a directory tree for the latest files that match "Data*.txt" but it is painfully slow. It's due to the fact I've had to nest the for loops (I suspect). Example directory tree: ROOT |-- |…
Jalcock501
  • 389
  • 2
  • 6
  • 18