hidden-files

Exclude hidden files from scandir

不打扰是莪最后的温柔 提交于 2019-11-27 14:56:34
I am using the following code to get a list of images in a directory: $files = scandir($imagepath); but $files also includes hidden files. How can I exclude them? mario On Unix, you can use preg_grep to filter out filenames that start with a dot: $files = preg_grep('/^([^.])/', scandir($imagepath)); I tend to use DirectoryIterator for things like this which provides a simple method for ignoring dot files: $path = '/your/path'; foreach (new DirectoryIterator($path) as $fileInfo) { if($fileInfo->isDot()) continue; $file = $path.$fileInfo->getFilename(); } function nothidden($path) { $files =

IOError: [Errno 13] Permission denied when trying to open hidden file in “w” mode

跟風遠走 提交于 2019-11-27 08:37:31
I want to replace the contents of a hidden file, so I attempted to open it in w mode so it would be erased/truncated: >>> import os >>> ini_path = '.picasa.ini' >>> os.path.exists(ini_path) True >>> os.access(ini_path, os.W_OK) True >>> ini_handle = open(ini_path, 'w') But this resulted in a traceback: IOError: [Errno 13] Permission denied: '.picasa.ini' However, I was able to achieve the intended result with r+ mode: >>> ini_handle = open(ini_path, 'r+') >>> ini_handle.truncate() >>> ini_handle.write(ini_new) >>> ini_handle.close() Q. What is the difference between the w and r+ modes, such

How can I grep hidden files?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 00:09:20
问题 I am searching through a Git repository and would like to include the .git folder. grep does not include this folder if I run grep -r search * What would be a grep command to include this folder? 回答1: Please refer to the solution at the end of this post as a better alternative to what you're doing. You can explicitly include hidden files (a directory is also a file). grep -r search * .* The * will match all files except hidden ones and .* will match only hidden files. However this will fail

How to ignore hidden files using os.listdir()?

混江龙づ霸主 提交于 2019-11-26 19:58:20
My python script executes an os.listdir(path) where the path is a queue containing archives that I need to treat one by one. The problem is that I'm getting the list in an array and then I just do a simple array.pop(0) . It was working fine until I put the project in subversion. Now I get the .svn folder in my array and of course it makes my application crash. So here is my question: is there an existing function that ignore hidden files when executing an os.listdir() and if not what would be the best way? Thank you. Adam Rosenfield You can write one yourself: def listdir_nohidden(path): for f

Exclude hidden files from scandir

情到浓时终转凉″ 提交于 2019-11-26 16:57:50
问题 I am using the following code to get a list of images in a directory: $files = scandir($imagepath); but $files also includes hidden files. How can I exclude them? 回答1: On Unix, you can use preg_grep to filter out filenames that start with a dot: $files = preg_grep('/^([^.])/', scandir($imagepath)); 回答2: I tend to use DirectoryIterator for things like this which provides a simple method for ignoring dot files: $path = '/your/path'; foreach (new DirectoryIterator($path) as $fileInfo) { if(

IOError: [Errno 13] Permission denied when trying to open hidden file in “w” mode

六月ゝ 毕业季﹏ 提交于 2019-11-26 14:13:02
问题 I want to replace the contents of a hidden file, so I attempted to open it in w mode so it would be erased/truncated: >>> import os >>> ini_path = '.picasa.ini' >>> os.path.exists(ini_path) True >>> os.access(ini_path, os.W_OK) True >>> ini_handle = open(ini_path, 'w') But this resulted in a traceback: IOError: [Errno 13] Permission denied: '.picasa.ini' However, I was able to achieve the intended result with r+ mode: >>> ini_handle = open(ini_path, 'r+') >>> ini_handle.truncate() >>> ini

How to ignore hidden files using os.listdir()?

落花浮王杯 提交于 2019-11-26 07:28:20
问题 My python script executes an os.listdir(path) where the path is a queue containing archives that I need to treat one by one. The problem is that I\'m getting the list in an array and then I just do a simple array.pop(0) . It was working fine until I put the project in subversion. Now I get the .svn folder in my array and of course it makes my application crash. So here is my question: is there an existing function that ignore hidden files when executing an os.listdir() and if not what would