directory-traversal

Scripts traversing through directories looking for specific set of files and folders

跟風遠走 提交于 2020-03-25 17:34:45
问题 I'm trying to create a script that will traverse through all folders and subfolders of rootDir looking for specific set of folders and files. If script will find the folder (for ex. testfolder1 ) in which there are: textfile.txt image.jpg (optionally) subtitles.dxfp another folder (ex. testsubfolder1 ) containing video.mp4 file (optionally) another folder (ex. testsubfolder2 ) containing video_trailer.mp4 file it will create archive containing textfile.txt , image.jpg , subtitles.dxfp (if

Python program to traverse directories and read file information

拈花ヽ惹草 提交于 2020-01-12 13:48:31
问题 I'm just getting started with Python but already have found it much more productive than Bash shell scripting. I'm trying to write a Python script that will traverse every directory that branches from the directory I launch the script in, and for each file it encounters, load an instance of this class: class FileInfo: def __init__(self, filename, filepath): self.filename = filename self.filepath = filepath The filepath attribute would be the full absolute path from root (/). Here's the

How to recursively scan directories in Android

痴心易碎 提交于 2019-12-18 06:58:03
问题 How can I recursively scan directories in Android and display file name(s)? I'm trying to scan, but it's slow (force close or wait). I'm using the FileWalker class given in a separate answer to this question. 回答1: You should almost always access the file system only from a non-UI thread. Otherwise you risk blocking the UI thread for long periods and getting an ANR. Run the FileWalker in an AsyncTask 's doInBackground() . This is a slightly optimized version of FileWalker: public class

How to traverse all the files in a directory; if it has subdirectories, I want to traverse files in subdirectories too

点点圈 提交于 2019-12-18 04:47:04
问题 opendir(DIR,"$pwd") or die "Cannot open $pwd\n"; my @files = readdir(DIR); closedir(DIR); foreach my $file (@files) { next if ($file !~ /\.txt$/i); my $mtime = (stat($file))[9]; print $mtime; print "\n"; } Basically I want to note the timestamp of all the txt files in a directory. If there is a subdirectory I want to include files in that subdirectory too. Can someone help me in modifying the above code so that it includes subdirectories too. if i am using the code below in windows iam

Copy directory using Qt

允我心安 提交于 2019-12-18 02:00:16
问题 I want to copy a directory from one drive to another drive. My selected directory contains many sub directories and files. How can I implement the same using Qt? 回答1: void copyPath(QString src, QString dst) { QDir dir(src); if (! dir.exists()) return; foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { QString dst_path = dst + QDir::separator() + d; dir.mkpath(dst_path); copyPath(src+ QDir::separator() + d, dst_path); } foreach (QString f, dir.entryList(QDir::Files)) {

Iterate directories in Perl, getting introspectable objects as result

烂漫一生 提交于 2019-12-14 02:37:06
问题 I'm about to start a script that may have some file lookups and manipulation, so I thought I'd look into some packages that would assist me; mostly, I'd like the results of the iteration (or search) to be returned as objects, which would have (base)name, path, file size, uid, modification time, etc as some sort of properties. The thing is, I don't do this all that often, and tend to forget APIs; when that happens, I'd rather let the code run on an example directory, and dump all of the

Opening many small files on NTFS is way too slow

て烟熏妆下的殇ゞ 提交于 2019-12-12 07:58:25
问题 I am writing a program that should process many small files, say thousands or even millions. I've been testing that part on 500k files, and the first step was just to iterate a directory which has around 45k directories in it (including subdirs of subdirs, etc), and 500k small files. The traversal of all directories and files, including getting file sizes and calculating total size takes about 6 seconds . Now, if I try to open each file while traversing and close it immediately it looks like

How to display all images of a directory in javascript?

折月煮酒 提交于 2019-12-10 20:33:36
问题 I want to display all images from a directory dynamically with the help of javascript. How can I do this? 回答1: I don't believe that it is possible, but if you make an AJAX request to an ASP.NET or PHP (or similar) page, they can list the files in the folder and return it for the Javascript to show. The cross-domain policy obviously applies. If you are using PHP, you should use recursion on directories to get the full file structure. PHP has a Scan Directory Function that you can use. Basic

Is os.walk() missing symlinks to directories?

南楼画角 提交于 2019-12-10 11:28:56
问题 I have a directory containing some files, some directories, some symlinks to files and some symlinks to directories. When I do os.walk() with followlinks=false in the directory, I get the files and symlinks to files in the filenames list and the directories in the dirnames list. But the symlinks to directories does not show up anywhere. Is this a bug or a feature in Python, or am I doing something wrong? I expect the symlinks to directories to show up in the filenames list, because they are

Is there some directory walker in Haskell?

安稳与你 提交于 2019-12-06 17:12:21
问题 Is there some recursive directory walker in Haskell so I could write something like listing <- walkDir "/tmp" I would not like to write my own. I can install some dependency from cabal but I want it to be cross platform (at least Linux and Windows). 回答1: Here is one way to list all Haskell files in a directory tree, using directory-tree that is not in a hidden directory (whose name starts with '.'): import Data.Traversable (traverse) import System.Directory.Tree ( AnchoredDirTree(..), DirTree