glob

Limitation to Python's glob?

流过昼夜 提交于 2019-12-11 01:48:07
问题 I'm using glob to feed file names to a loop like so: inputcsvfiles = glob.iglob('NCCCSM*.csv') for x in inputcsvfiles: csvfilename = x do stuff here The toy example that I used to prototype this script works fine with 2, 10, or even 100 input csv files, but I actually need it to loop through 10,959 files. When using that many files, the script stops working after the first iteration and fails to find the second input file. Given that the script works absolutely fine with a "reasonable" number

List comprehension with if conditional to get list of files of a specific type

心已入冬 提交于 2019-12-10 23:43:16
问题 Roughly following the logic for putting together list comprehensions with an if-else described in this solution, I am trying to get a list of files with a specific extensions under a parent directory. Here is the long form of the code: mxd_list = [] for top_dir, dir_list, obj_list in os.walk(top_path): for obj in obj_list: if obj.endswith('.mxd'): mxd_list.append(os.path.join(top_dir, obj)) This is my current attempt at consolidating this using a list comprehension. Although it runs, the list

python glob issues with directory with [] in name

此生再无相见时 提交于 2019-12-10 23:28:43
问题 I am using glob to find all *.shp files within a directory, but the directory name contains '[]' and that is causing glob to fail. Any workarounds for this? My code is: glob.glob(sub_dir+os.sep+'soilmu_a_*.shp') where sub_dir is: 'C:\\Users\\oh\\wss_SSA_OH001_soildb_OH_2003_[2013-12-19]\\spatial\\' The error message I get is: *** error: bad character range 回答1: As suggested in the manual page, you can modify your pattern and wrap the offending meta characters. Change [ to [[] and ] to []]

How to specify multiple input paths to a Dataflow job

情到浓时终转凉″ 提交于 2019-12-10 21:25:20
问题 I want to run a Dataflow job over multiple inputs from Google Cloud Storage, but the paths I want to pass to the job can't be specified with just the * glob operator. Consider these paths: gs://bucket/some/path/20160208/input1 gs://bucket/some/path/20160208/input2 gs://bucket/some/path/20160209/input1 gs://bucket/some/path/20160209/input2 gs://bucket/some/path/20160210/input1 gs://bucket/some/path/20160210/input2 gs://bucket/some/path/20160211/input1 gs://bucket/some/path/20160211/input2 gs:/

How do I hide all excluding a file type

一个人想着一个人 提交于 2019-12-10 21:05:17
问题 I'm trying to hide all my files excluding .exe. Below hides : files, exe Does not hide: folders I want : Hide folders, files Does not hide: .exe import os, shutil import ctypes folder = 'C:\\Users\\TestingAZ1' for the_file in os.listdir(folder): file_path = os.path.join(folder, the_file) try: if os.path.isfile(file_path): ctypes.windll.kernel32.SetFileAttributesW(file_path, 2) except Exception as e: print(e) I cannot use -onefile due to large size for each exe. 回答1: You almost got it ;)

Looping through big files takes hours in Python

醉酒当歌 提交于 2019-12-10 20:37:48
问题 This is my second day working in Python .I worked on this in C++ for a while, but decided to try Python. My program works as expected. However, when I process one file at a time without the glob loop, it takes about a half hour per file. When I include the glob, the loop takes about 12 hours to process 8 files. My question is this, is there anything in my program that is definitely slowing it down? is there anything I should be doing to make it faster? I have a folder of large files. For

What is the proper way to get the karma test coverage path into Travis CI?

删除回忆录丶 提交于 2019-12-10 20:24:49
问题 I'm using karma to run unit tests and generate coverage reports. That all works fine but I want to publish the lcov.info file to Code Climate from Travis CI. I've done it before and it works great, but the url from that test runner was static. The issue is that karma creates a subfolder for each instance it runs such as test/coverage/PhantomJS 1.9.7 (Mac OS X)/lcov.info . Is there a clean way to get that url to feed into travis? I don't want to have to remember to update a hardcoded value

php--glob for searching directories and .jpg only

丶灬走出姿态 提交于 2019-12-10 18:44:22
问题 What if I want to search for a only subdirectories AND certain file types. Ex. I have a folder named “stuff” where random stuff is uploaded. And say I want to search for just subfolders AND .jpg files within “stuff” and nothing more. I know to search for only .jpg is… $array = glob(‘stuff/{*.jpg}’, GLOB_BRACE); and to search for only subdirectories is… $array = glob(‘stuff/*’, GLOB_ONLYDIR); …but how do I combine the two without getting any other unwanted files? Is there a pattern for

php foreach and glob() function

时光总嘲笑我的痴心妄想 提交于 2019-12-10 18:32:48
问题 PHP versione 5.2.* my function not working :/ images in server, in folder: /public_html/gallery/images <?php foreach(glob('gallery/images/*', GLOB_NOSORT) as $image) { echo "Filename: " . $image . "<br />"; } ?> any help? what im doing wrong? error i get is : Warning: Invalid argument supplied for foreach() in /home/a9773555/public_html/gallery/index.php on line 2 回答1: The problem looks you have put your php file in gallery folder... /home/a9773555/public_html/gallery/index.php on line 2 if

Glob that doesn't match anything expands to itself, rather than to nothing

不打扰是莪最后的温柔 提交于 2019-12-10 16:25:04
问题 I want to iterate over the files in a folder of a special type (like .test ): So I wrote a little script names for_loop : for f in *.test do echo 'This is f: '${f} done After ( chmod +x for_loop ) I can start it with ./for_loop . If there are .test -files, everthing is fine, BUT if there is no file in the folder that matches *.test , the for-loop is still executed once. In this case the output looks like: This is f: *.test But I thought that if there were no files in the folder that match the