glob

Is there an easy way to set nullglob for one glob

烂漫一生 提交于 2019-12-20 12:07:08
问题 In bash, if you do this: mkdir /tmp/empty array=(/tmp/empty/*) you find that array now has one element, "/tmp/empty/*" , not zero as you'd like. Thankfully, this can be avoided by turning on the nullglob shell option using shopt -s nullglob But nullglob is global, and when editing an existing shell script, may break things (e.g., did someone check the exit code of ls foo* to check if there are files named starting with "foo"?). So, ideally, I'd like to turn it on only for a small scope

Python 3 unicode encode error

橙三吉。 提交于 2019-12-20 06:24:28
问题 I'm using glob.glob to get a list of files from a directory input. When trying to open said files, Python fights me back with this error: UnicodeEncodeError: 'charmap' codec can't encode character '\xf8' in position 18: character maps to < undefined > By defining a string variable first, I can do this: filePath = r"C:\Users\Jørgen\Tables\\" Is there some way to get the 'r' encoding for a variable? EDIT: import glob di = r"C:\Users\Jørgen\Tables\\" def main(): fileList =

Perl glob returning a false positive

对着背影说爱祢 提交于 2019-12-20 05:54:53
问题 What seemed liked a straightforward piece of code most certainly didn't do what I wanted it to do. Can somebody explain to me what it does do and why? my $dir = './some/directory'; if ( -d $dir && <$dir/*> ) { print "Dir exists and has non-hidden files in it\n"; } else { print "Dir either does not exist or has no non-hidden files in it\n"; } In my test case, the directory did exist and it was empty. However, the then (first) section of the if triggered instead of the else section as expected.

pass wildcard to cut command in shell script and store it in a variable

纵然是瞬间 提交于 2019-12-20 05:23:18
问题 I am new to shell, I have a case where I am trying to evaluate a particular column unique values to check if they are valid in a shell script which will be invoked later. From my searches I think cut along with sort & unique is good to do it So my attempt is file=/filepath/*vendor.csv file_categories = `cut -d, -f1 $file |sort |unique` $file should hold file which has vendor in its filename but even after using command substitution (`) the $file is not getting replaced with the correct

PHP recursive directory search using glob for multiple file types

痞子三分冷 提交于 2019-12-20 04:56:14
问题 I have a bunch of folders with these file types spread across them .mp4, .flv, .wmv, .mov /video/o/y/oyr800/clips/1.flv /video/p/y/pyr800/clips/1.wmv /video/q/y/qyr800/clips/1.mp4 /video/51/51.mov /video/52/52.flv I tried using this function to list the paths and filenames but it gives me a blank return: print_r(rglob('{*.mp4,*.flv,*.wmv,*.mov}',GLOBAL_BRACE)); function rglob($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB

Weird behavior of BASH glob/regex ranges

天大地大妈咪最大 提交于 2019-12-20 02:29:06
问题 I'm seeing BASH bracket ranges (e.g. [A-Z]) behaving in an unexpected way. Is there's an explanation for such behavior, or it is a bug? Let's say I have a variable, from which I want to strip all uppercase letters: $ var='ABCDabcd0123' $ echo "${var//[A-Z]/}" The result I get is this: a0123 If I do it with sed , I get an expected result: $ echo "${var}" | sed 's/[A-Z]//g' abcd0123 The same seems to be the case for BASH built-in regex match: $ [[ a =~ [A-Z] ]] ; echo $? 1 $ [[ b =~ [A-Z] ]] ;

ordered with glob.glob in python [duplicate]

风格不统一 提交于 2019-12-19 09:04:21
问题 This question already has answers here : Does Python have a built in function for string natural sort? (16 answers) Closed 5 years ago . I have a list of file: foo_00.txt foo_01.txt foo_02.txt foo_03.txt foo_04.txt foo_05.txt foo_06.txt foo_07.txt foo_08.txt foo_09.txt foo_10.txt foo_11.txt ......... ......... foo_100.txt foo_101.txt when i use import glob PATH = "C:\testfoo" listing = glob.glob(os.path.join(PATH, '*.txt')) i have this order foo_00.txt foo_01.txt foo_02.txt foo_03.txt foo_04

Why do we need the GLOB clause in SQLite?

半城伤御伤魂 提交于 2019-12-19 05:35:12
问题 I'm an Android developer and recently came across the GLOB clause in SQLite. I cannot understand why we need GLOB given that LIKE is already in place. Both clauses have wildcards to represent single and multiple characters. The only difference is that GLOB is case sensitive. But is that all? Are there any queries where LIKE is a bad or inappropriate choice? Are there any cases where we absolutely have to use GLOBE vs LIKE or vice versa? 回答1: Case sensitivity is useful by itself, because this

Why do we need the GLOB clause in SQLite?

ⅰ亾dé卋堺 提交于 2019-12-19 05:35:04
问题 I'm an Android developer and recently came across the GLOB clause in SQLite. I cannot understand why we need GLOB given that LIKE is already in place. Both clauses have wildcards to represent single and multiple characters. The only difference is that GLOB is case sensitive. But is that all? Are there any queries where LIKE is a bad or inappropriate choice? Are there any cases where we absolutely have to use GLOBE vs LIKE or vice versa? 回答1: Case sensitivity is useful by itself, because this

What pattern does .gitignore follow?

蹲街弑〆低调 提交于 2019-12-19 05:16:09
问题 Here is the content of my current directory. $ ls foo.foo $ ls -a . .. .bar.foo .foo foo.foo .gitignore Then I turn this directory into a git repository. $ git init Initialized empty Git repository in /home/lone/foo/.git/ $ ls -a . .. .bar.foo .foo foo.foo .git .gitignore Here is the content of .gitignore . $ cat .gitignore *.foo I see that the pattern in .gitignore behaves differently from the same pattern in shell. In the shell *.foo matches only non-hidden files, i.e. filenames that do not