directory

Deleting directory in Python

主宰稳场 提交于 2019-12-17 10:55:25
问题 shutil.rmtree will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain? 回答1: shutil.rmtree can take an error-handling function that will be called when it has problem removing a file. You can use that to force the removal of the problematic file(s). Inspired by http://mail.python.org/pipermail/tutor/2006-June/047551.html and http://techarttiki.blogspot.com/2008/08/read-only-windows-files-with-python.html: import os import stat

How to check if a directory/file/symlink exists with one command in Ruby

微笑、不失礼 提交于 2019-12-17 10:46:58
问题 Is there a single way of detecting if a directory/file/symlink/etc. entity (more generalized) exists? I need a single function because I need to check an array of paths that could be directories, files or symlinks. I know File.exists?"file_path" works for directories and files but not for symlinks (which is File.symlink?"symlink_path" ). 回答1: The standard File module has the usual file tests available: RUBY_VERSION # => "1.9.2" bashrc = ENV['HOME'] + '/.bashrc' File.exist?(bashrc) # => true

Makefile to put object files from source files different directories into a single, separate directory?

ぐ巨炮叔叔 提交于 2019-12-17 10:34:38
问题 I'm using UnitTest++ to allow me to create unit tests for some C++ code (that should build on Linux or Mac OS X). I have a directory structure like this: src - Foo.cpp - Bar.cpp test - FooTest.cpp - BarTest.cpp - Main.cpp - Makefile UnitTest++ - libUnitTest++.a And this Makefile (adapted from the UnitTest++ Makefile) works nicely (with GNU make): test = TestFooAndBar src = ../src/Foo.cpp \ ../src/Bar.cpp test_src = Main.cpp \ FooTest.cpp \ BarTest.cpp lib = ../UnitTest++/libUnitTest++.a

ZIP all files in directory and download generated .zip

爱⌒轻易说出口 提交于 2019-12-17 10:27:13
问题 Well, first of all, this is my folder structure: images/ image1.png image11.png image111.png image223.png generate_zip.php And this is mine generate_zip.php: <?php $files = array($listfiles); $zipname = 'adcs.zip'; $zip = new ZipArchive; $zip->open($zipname, ZipArchive::CREATE); foreach ($files as $file) { $zip->addFile($file); } $zip->close(); header('Content-Type: application/zip'); header("Content-Disposition: attachment; filename='adcs.zip'"); header('Content-Length: ' . filesize($zipname

Getting Downloads Folder in C#? [duplicate]

Deadly 提交于 2019-12-17 10:17:17
问题 This question already has answers here : How to programmatically derive windows downloads folder “%USERPROFILE%/Downloads”? (6 answers) Closed 2 years ago . I have made some code that will search directories and display files in a listbox. DirectoryInfo dinfo2 = new DirectoryInfo(@"C:\Users\Hunter\Downloads"); FileInfo[] Files2 = dinfo2.GetFiles("*.sto"); foreach (FileInfo file2 in Files2) { listBox1.Items.Add(file2.Name); } I have even tried this: string path = Environment.SpecialFolder

How to use Bash to create a folder if it doesn't already exist?

五迷三道 提交于 2019-12-17 10:15:47
问题 #!/bin/bash if [!-d /home/mlzboy/b2c2/shared/db]; then mkdir -p /home/mlzboy/b2c2/shared/db; fi; This doesn't seem to work. Can anyone help? 回答1: First, in bash "[" is just a command, which expects string "]" as a last argument, so the whitespace before the closing bracket (as well as between "!" and "-d" which need to be two separate arguments too) is important: if [ ! -d /home/mlzboy/b2c2/shared/db ]; then mkdir -p /home/mlzboy/b2c2/shared/db; fi Second, since you are using -p switch to

How to delete empty folders using windows command prompt?

你。 提交于 2019-12-17 10:12:57
问题 I need to delete all empty folders from my application folder using windows command prompt? How can I create a bat file like that? Please help me. 回答1: for /f "usebackq" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d" from: http://blogs.msdn.com/b/oldnewthing/archive/2008/04/17/8399914.aspx Of course I'd test it first without deleting before I do that command. Also, here's a modded version from the comments that includes folders with spaces: for /f "usebackq delims=" %%d in (`"dir /ad/b/s |

Deny access to specific file types in specific directory

青春壹個敷衍的年華 提交于 2019-12-17 09:47:49
问题 For some application, users are able to upload their own files. Since this can be very large files, they are allowed to upload them via their own FTP client. Of course I wouldn't like them to upload some PHP files with which they can access all other files on the server. One of the ways I want to prevent this behavior is by denying access to specific file types (like php, rb, py, etc.) only in these folders. I have found ways to deny access to folders, to files, to files in folders, but

Why is it whenever I use scandir() I receive periods at the beginning of the array?

為{幸葍}努か 提交于 2019-12-17 09:46:53
问题 Why is it whenever I use scandir() I receive periods at the beginning of the array? Array ( [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ) Array ( [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ) 回答1: Those are the current ( . ) and parent ( .. ) directories. They are present in all directories, and are used to refer to the directory itself and its direct parent. 回答2: There are two entries present in every directory listing: . refers to the current

How can I display images from a specific folder on android gallery

不想你离开。 提交于 2019-12-17 09:46:01
问题 How can I display all images from a specific folder on android gallery like, for example, whatapp does. I`m using MediaScannerConnectionClient File folder = new File("/sdcard/myfolder/"); allFiles = folder.list(); SCAN_PATH=Environment.getExternalStorageDirectory().toString()+"/myfolder/"+allFiles[0]; @Override public void onScanCompleted(String path, Uri uri) { try { if (uri != null) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); } } finally {