glob

How do I test whether a string would match a glob in Ruby?

二次信任 提交于 2019-12-19 05:03:15
问题 Without hitting the filesystem, is it possible to see whether the glob "foo*" would match "food" in Ruby? Background : one of my scripts produce files, and I'd like to unit test that other scripts would be able to detect such files with their current glob. 回答1: Yes, it is possible using the fnmatch method: File.fnmatch("foo*", "food") #=> true 来源: https://stackoverflow.com/questions/7186361/how-do-i-test-whether-a-string-would-match-a-glob-in-ruby

Bash extracting file basename from long path

我与影子孤独终老i 提交于 2019-12-18 19:15:27
问题 In bash I am trying to glob a list of files from a directory to give as input to a program. However I would also like to give this program the list of filenames files="/very/long/path/to/various/files/*.file" So I could use it like that. prompt> program -files $files -names $namelist If the glob gives me : /very/long/path/to/various/files/AA.file /very/long/path/to/various/files/BB.file /very/long/path/to/various/files/CC.file /very/long/path/to/various/files/DD.file /very/long/path/to

PHP code to exclude index.php using glob

我们两清 提交于 2019-12-18 14:52:51
问题 Problem I am trying to display a random page from a file called ../health/ In this file there is a index.php file and 118 other files named php files. I would like to randomly display a file from the health folder but i would like it to exclude the index.php file. This following code includes the index.php file sometimes. I have also tried altering the $exclude line to show ../health/index.php but still no luck. <?php $exclude = array("index.php"); // can add more here later $answer = array

Assign results of globbing to a variable in Bash

痞子三分冷 提交于 2019-12-18 13:55:09
问题 My colleague, Ryan, came to me with a bug in his Bash script, and I identified the problem with this test: $ mkdir ryan $ mkdir ryan/smells-bad $ FOO=ryan/smells-* $ echo $FOO ryan/smells-bad $ touch $FOO/rotten_eggs touch: cannot touch `ryan/smells-*/rotten_eggs': No such file or directory From this I infer that the globbing happens during the echo command, not when the variable FOO is created. We have a couple of workarounds, in descending order of ungracefulness: touch `echo $FOO`/rotten

Read multiple csv files and Add filename as new column in pandas

半腔热情 提交于 2019-12-18 13:19:54
问题 I have several csv files in a single folder and I want to open them all in one dataframe and insert a new column with the associated filename. So far I've coded the following: import pandas as pd import glob, os df = pd.concat(map(pd.read_csv, glob.glob(os.path.join('path/*.csv')))) df['filename']= os.path.basename(csv) df This gives me the dataframe I want but in the new column 'filename' it's only listing the last filename in the folder for every row. I'm looking for each row to be

Is there a way to glob() only files?

流过昼夜 提交于 2019-12-18 12:45:43
问题 I know that glob can look for all files or only all directories inside a folder : echo "All files:\n"; $all = glob("/*"); var_dump($all); echo "Only directories\n"; $dirs = glob("/*", GLOB_ONLYDIR); var_dump($dirs); But I didn't found something to find only files in a single line efficiently. $files = array_diff(glob("/*"), glob("/*", GLOB_ONLYDIR)); Works well but reads directory twice (even if there are some optimizations that make the second browsing quicker). 回答1: I finally found a

OmniAuth doesn't work with Route Globbing in Rails3

為{幸葍}努か 提交于 2019-12-18 11:35:59
问题 I am trying to follow the Railscast 241 Simple OmniAuth and it works fine unless I have Route Globbing at the end of /config/routes.rb : match '*uri' => "posts#index" If I request /auth/twitter with the globbing then OmniAuth does nothing: Started GET "/auth/twitter" for 127.0.0.1 at 2011-04-03 19:17:44 +0200 Processing by PostsController#index as HTML Parameters: {"uri"=>"auth/twitter"} Rendered posts/index.html.haml within layouts/application (9.0ms) Completed 200 OK in 103ms (Views: 14.6ms

Globbing/pathname expansion with colon as separator

我的未来我决定 提交于 2019-12-18 11:23:10
问题 How can I convert a string containing glob characters such as /var/lib/gems/*/bin into a colon-separated string of filenames (i.e. PATH compatible) matching the pattern? i.e. echo /var/lib/gems/*/bin will return /var/lib/gems/1.8/bin /var/lib/gems/1.9.1/bin I want /var/lib/gems/1.8/bin:/var/lib/gems/1.9.1/bin instead. The obvious approach is simply to replace the space character with ':' via tr , but that doesn't work if the filename itself contains the space character. 回答1: Actually, I

Is the order of iteration in bash for loop guaranteed? [duplicate]

天涯浪子 提交于 2019-12-18 06:56:57
问题 This question already has an answer here : What sort order does Linux use? (1 answer) Closed 3 years ago . Let's say I have a for loop in bash which looks like this: for i in $MYDIR/*.jar do # do something with files done Is the order of iteration guaranteed, i.e. will the loop always process files in same order? If it is guaranteed, is the order alphabetical? 回答1: According to the bash man page: Pathname Expansion After word splitting, unless the -f option has been set, bash scans each word

Get all file all subfolders and all hidden file with glob

别来无恙 提交于 2019-12-18 04:12:46
问题 In my recurive function to zip a whole folders i have this piece of code glob($path. '/*') that give me all files and subfolders matching my $path. Here I read that with glob I can get even hidden files ".filename" with glob('{,.}*', GLOB_BRACE) How to merge in one expression my needs? I tried glob('{/,.}*', GLOB_BRACE) but only give me the files I tried glob('{/,.,}*', GLOB_BRACE) but I get crazy results I already filteres . and .. How to merge glob($dir . '/*') and glob('{,.}*', GLOB_BRACE)