How to use to find files recursively?

There are a couple of ways: pathlib.Path().rglob() Use pathlib.Path().rglob() from the pathlib module, which was introduced in Python 3.5. from pathlib import Path for path in Path(‘src’).rglob(‘*.c’): print(path.name) glob.glob() If you don’t want to use pathlib, use glob.glob(): from glob import glob for filename in glob(‘src/**/*.c’, recursive=True): print(filename) For cases where matching files beginning with … Read more

What reasons are there to prefer glob over readdir (or vice-versa) in Perl?

You missed the most important, biggest difference between them: glob gives you back a list, but opendir gives you a directory handle. You can pass that directory handle around to let other objects or subroutines use it. With the directory handle, the subroutine or object doesn’t have to know anything about where it came from, … Read more

glob pattern matching in .NET

I like my code a little more semantic, so I wrote this extension method: using System.Text.RegularExpressions; namespace Whatever { public static class StringExtensions { /// <summary> /// Compares the string against a given pattern. /// </summary> /// <param name=”str”>The string.</param> /// <param name=”pattern”>The pattern to match, where “*” means any sequence of characters, and “?” … Read more

Recursively add files by pattern

You can use git add [path]/\*.java to add java files from subdirectories, e.g. git add ./\*.java for current directory. From git add documentation: Adds content from all *.txt files under Documentation directory and its subdirectories: $ git add Documentation/\*.txt Note that the asterisk * is quoted from the shell in this example; this lets the … Read more

How to implement glob in C#

/// <summary> /// return a list of files that matches some wildcard pattern, e.g. /// C:\p4\software\dotnet\tools\*\*.sln to get all tool solution files /// </summary> /// <param name=”glob”>pattern to match</param> /// <returns>all matching paths</returns> public static IEnumerable<string> Glob(string glob) { foreach (string path in Glob(PathHead(glob) + DirSep, PathTail(glob))) yield return path; } /// <summary> /// uses … Read more

glob exclude pattern

The pattern rules for glob are not regular expressions. Instead, they follow standard Unix path expansion rules. There are only a few special characters: two different wild-cards, and character ranges are supported [from pymotw: glob – Filename pattern matching]. So you can exclude some files with patterns. For example to exclude manifests files (files starting … Read more