How do I read in the contents of a directory in Perl?

opendir(D, “/path/to/directory”) || die “Can’t open directory: $!\n”; while (my $f = readdir(D)) { print “\$f = $f\n”; } closedir(D); EDIT: Oh, sorry, missed the “into an array” part: my $d = shift; opendir(D, “$d”) || die “Can’t open directory $d: $!\n”; my @list = readdir(D); closedir(D); foreach my $f (@list) { print “\$f = … Read more

Best way to determine if two path reference to same file in C#

As far as I can see (1) (2) (3) (4), the way JDK7 does it, is by calling GetFileInformationByHandle on the files and comparing dwVolumeSerialNumber, nFileIndexHigh and nFileIndexLow. Per MSDN: You can compare the VolumeSerialNumber and FileIndex members returned in the BY_HANDLE_FILE_INFORMATION structure to determine if two paths map to the same target; for example, … Read more

Distributed File Systems: GridFS vs. GlusterFS vs Ceph vs HekaFS Benchmarks [closed]

I’m not sure your list is quite correct. It depends on what you mean by a file system. If you mean a file system that is mountable in an operating system and usable by any application that reads and writes files using POSIX calls, then GridFS doesn’t really qualify. It is just how MongoDB stores … Read more

Does the .net framework provides async methods for working with the file-system?

Does the .net framework has an async built-in library/assembly which allows to work with the file system Yes. There are async methods for working with the file system but not for the helper methods on the static File type. They are on FileStream. So, there’s no File.ReadAllBytesAsync but there’s FileStream.ReadAsync, etc. For example: byte[] result; … Read more

How to get list of files with a specific extension in a given folder?

#define BOOST_FILESYSTEM_VERSION 3 #define BOOST_FILESYSTEM_NO_DEPRECATED #include <boost/filesystem.hpp> namespace fs = boost::filesystem; /** * \brief Return the filenames of all files that have the specified extension * in the specified directory and all subdirectories. */ std::vector<fs::path> get_all(fs::path const & root, std::string const & ext) { std::vector<fs::path> paths; if (fs::exists(root) && fs::is_directory(root)) { for (auto const & … Read more

How do I mock the filesystem in Python unit tests?

pyfakefs (homepage) does what you want – a fake filesystem; it’s third-party, though that party is Google. See How to replace file-access references for a module under test for discussion of use. For mocking, unittest.mock is the standard library for Python 3.3+ (PEP 0417); for earlier version see PyPI: mock (for Python 2.5+) (homepage). Terminology … Read more