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
2
votes
2 answers

Separate plain filenames from fnmatch patterns in python

My python function is given a (long) list of path arguments, each of which can possibly be a glob. I make a pass over this list using glob.glob to extract all the matching filenames, like this: files = [filename for pattern in patterns for filename…
amaurea
  • 4,950
  • 26
  • 35
1
vote
1 answer

Why does Ruby's fnmatch not match file in subdirs with FNM_PATHNAME?

Gitlab CI uses this code for globs: File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB) If I want to match all files and folders under a directory I think you have to do this: foo/* foo/**/* That sucks. I thought…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
1
vote
1 answer

Azure CLI - az storage file delete-batch: pattern for all but one specific file

I'm trying to delete all files from an Azure Storage File share and exclude one specific file name. I just can't figure out the pattern. I've tried this but the pattern doesn't match anything now. az storage file delete-batch --source…
silent
  • 14,494
  • 4
  • 46
  • 86
1
vote
2 answers

fnmatches fails to match '?' to zero occurences

I'm writing a basic test for fnmatch before integrating in my code. Here is the test: int main (int argc, char *argv[]) { for (int i = 2; i < argc; i++) if (!fnmatch(argv[1], argv[i], 0)) printf("%s matches %s\n", argv[i],…
0sharp
  • 43
  • 6
1
vote
0 answers

Process 100 of feature classes through script and feature class name to end of each output

NOTE: Work constraints I must use python 2.7 (I know - eyeroll) and standard modules. I'm still learning python. I have about 100 tiled 'area of interest' polygons in a geodatabase that need to be processed through my script. My script has been…
1
vote
2 answers

How to get the full name of a Folder with just its first 10 characters

So, I have the following application... I have a folder with more than ten thousand folders on it. Each folder is a job and all of them have the same format: "ten digits" + _ + "the name of the job" Like this: "1234567890_Stackoverflow" How can I…
1
vote
1 answer

Query about the Python fnmatch module?

I was searching for the fnmatch module, and along the way, I came across a statement where I didn’t get what is happening… can anyone help me? I need to know what purpose the -25 serves in this code: print 'Filename: %-25s %s' % (name,…
1
vote
2 answers

fnmatch usage with complicate pattern C

I'm only able to match simple patterns like: "[0-9]" with fnmatch("[0-9]", tocheck, 0). If I try something more complicated with ? or . or even a combination of these how do I use fnmatch? I saw there are some flags that can do the trick, but I…
sanchu
  • 11
  • 1
  • 3
1
vote
2 answers

Python fnmatch, check exist file

I have a task, I wanna check if exist special file *.part in directory. If file exist do check again, if not, print "file was deleted". I use os.listdir(), next for each file in lisdir, I use fnmatch(file, '*.part'),next again get lisdir and…
0
votes
3 answers

Is it possible to glob for *.yaml and *.yml files in one pattern?

How to find all .yml and .yaml files using a single glob pattern? Desired output: >>> import os, glob >>> os.listdir('.') ['f1.yaml', 'f2.yml', 'f0.txt'] >>> glob.glob(pat) ['f1.yaml', 'f2.yml'] Attempts that don't work: >>>…
no step on snek
  • 324
  • 1
  • 15
0
votes
2 answers

fnmatch - single pattern to allow only text which have dots and digits

In GitHub I want to protect branches which have digits and dots. But if a branch has any letters, than it should not be protected need fnmatch pattern so text with digits separated with dots will be matched matched…
VextoR
  • 5,087
  • 22
  • 74
  • 109
0
votes
1 answer

python fnmatch exclude path with string

I want to perform check and allow access to only specific pattern URLs and exclude few. Using the following check to match for the allowed URLs ALLOWED_URL = [ '/auth/*' ] and using fnmatch to match the pattern any(fnmatch(request.path, p) for p…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
0
votes
1 answer

How get on same time count list files and files adress?

i need to ask if possible and how get on same time the sum of list files in directory and subdirectory with fnmatch filter and files adress. I use for now this: def return_ext(): file_pasok = ["AAAAA.txt", "BBBBBB.txt"] for i in…
Massimo B.
  • 23
  • 6
0
votes
2 answers

finding matches between a) all the files in a directory and b) a txt list of files not working with fnmatch - python

So I've got the code below and when I run tests to spit out all the files in A1_dir and A2_list, all of the files are showing up, but when I try to get the fnmatch to work, I get no results. For background in case its helpful: I am trying to comb…
alexdobrenko
  • 11
  • 1
  • 3
0
votes
1 answer

fnmatch - Matching for Patterns using quantifiers and other regex options

Hope you are all doing well. I am currently using fnmatch to match for file names against patterns. I have not had any issues with simple patterns involving *,?,[seq] as mentioned in the fnmatch documentation. However I am not able to figure out a…
rainingdistros
  • 450
  • 3
  • 11