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

Not listing the file specified in regex with fnmatch

I am trying to list only specified files in my directory but getting only empty results. When I checked the expected results with regex tester (https://regex101.com/), I've got the expected results. But in the python code, I can see nothing. I…
BedSon
  • 47
  • 1
  • 7
0
votes
2 answers

Python: If filename in specified path contains string, then move to folder

New to python here. I would like to create a script that will scan my directory and if the filename contains a certain string in it, then it will automatically move to a folder of my choice. Have tried this, but to no luck: import os import…
patriciajlim
  • 53
  • 2
  • 3
  • 9
0
votes
1 answer

Reading file from directory based on the selected filename on the list

I have a large number of 2-dimensional files from which I am calculating an XX parameter as listed below. '2019-10-12_17-43.csv', '2019-10-12_17-42.csv', '2019-10-12_17-41.csv', '2019-10-12_17-44.csv', '2019-10-12_17-40.csv', …
Basant
  • 19
  • 8
0
votes
2 answers

How to get filepaths that match a glob without having them on the filesystem

I have a list of filepaths relative to a root directory, and am trying to determine which would be matched by a glob pattern. I'm trying to get the same results that I would get if all the files were on my filesystem and I ran…
movermeyer
  • 1,502
  • 2
  • 13
  • 19
0
votes
1 answer

How to check if the same file name matches in 2 directories and append it using python?

I have 2 directories with multiple files(read as CSV). The filename denotes a particular customer number. I read the files as follows, for dirpath, dirs, files in os.walk("/path/to/file/"): for file in files: …
Amogh Katwe
  • 196
  • 11
0
votes
1 answer

Trying to match a Regex filename from a list of FTP files

I'm trying to create a conditional download from an ftp for daily files, I'm struggling to get regex to work with on file that has unique time stamps to match properly and get downloaded. Here's what I have. Example file…
0
votes
1 answer

Is fnmatch.fnmatch incompatible to the Unix pattern filematching syntax?

I am using Python 3.7.6 and the fnmatch.fnmatch function to match a filename with a given pattern. Most of my tests worked, but in specific the following example doesn't return the value as expected. Give is the following exanoke: >…
HelloWorld
  • 2,392
  • 3
  • 31
  • 68
0
votes
1 answer

Working with multiple filename patterns in python

I'm struggling to get a couple of things together as, since I've got a code together that works with a particular file pattern (i.e FILENAME_IDENTIFIER_NUMBER.filetype) I have some old files that do not match this particular filename structure that…
Graham
  • 17
  • 1
  • 7
0
votes
0 answers

Moving Files from Path in Pandas Data Frame

I have a folder with about 600,000 photos in it. I need to move a select 500 of those photos. I have a dataframe with those file paths as values in one of the columns. I need to be able to loop through that data frame, pluck out the specific image…
Jordan
  • 1,415
  • 3
  • 18
  • 44
0
votes
1 answer

Dynamic fnmatch pattern via variable or combination of pattern match and variable

I'm trying to figure out the best way to store a dynamic or changing value in a variable and use the variable as part of my pattern search in fnmatch. Quite possibly fnmatch is not the right way to go? Trying to keep this as simple as possible. I'm…
0
votes
1 answer

Why is there a no file found error while moving files within loop with shututil?

I am trying to organize files into specific folders by using fnmatch but for some reason the the files are not able to be moved or copied once they go through the loop I wrote. I made sure that every directory is correctly named and printed to check…
user7742147
-1
votes
1 answer

python fnmatch.fnmatch("[seq]") escape not working

According to the https://bugs.python.org/issue13929, "[seq]" should be escaped by the backslash. However, when i run the same code, i have different result like bellow I need to detect the string contains the "[" and "]". So, my solution is to…
mal mal
  • 11
  • 4
-1
votes
1 answer

is it possible to use fnmatch.filter on a pandas dataframe instead of regex?

I have a dataframe as below for example, i want to have only tests with certain regex to be part of my updated dataframe. I was wondering if there is a way to do it with fnmatch instead of regex? data = {'part1':[0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0,…
-1
votes
1 answer

Python glob does not find any results

I am trying to extract some data from a text file. Those are the line of code: directory = './mydirec' files = glob('{0:s}/*.gather.txt'.format(directory)) I keep receiving [] , so no results. Someone can help me to understand why? Thanks
-1
votes
1 answer

Is there a way to apply FNM_PATHNAME flag of fnmatch only for first instance of slash?

Hi I am trying to come up with a means to perform wildcard masking using fnmatch with certain rules. on finding first instance of slash '/' in string, it has to be matched exactly with slash ('/') in the pattern. i.e wildcard ('*') will not be able…
RBS
  • 3
  • 2
1 2 3
4