directory-traversal

Copy directory using Qt

冷暖自知 提交于 2019-11-28 23:12:04
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? 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)) { QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f); } } Manually, you can do the next things

Perform an action in every sub-directory using Bash

筅森魡賤 提交于 2019-11-27 16:54:01
I am working on a script that needs to perform an action in every sub-directory of a specific folder. What is the most efficient way to write that? for D in `find . -type d` do //Do whatever you need with D done kanaka A version that avoids creating a sub-process: for D in *; do if [ -d "${D}" ]; then echo "${D}" # your processing here fi done Or, if your action is a single command, this is more concise: for D in *; do [ -d "${D}" ] && my_command; done Or an even more concise version ( thanks @enzotib ). Note that in this version each value of D will have a trailing slash: for D in */; do my

Perform an action in every sub-directory using Bash

扶醉桌前 提交于 2019-11-26 18:47:04
问题 I am working on a script that needs to perform an action in every sub-directory of a specific folder. What is the most efficient way to write that? 回答1: for D in `find . -type d` do //Do whatever you need with D done 回答2: A version that avoids creating a sub-process: for D in *; do if [ -d "${D}" ]; then echo "${D}" # your processing here fi done Or, if your action is a single command, this is more concise: for D in *; do [ -d "${D}" ] && my_command; done Or an even more concise version

Preventing Directory Traversal in PHP but allowing paths

て烟熏妆下的殇ゞ 提交于 2019-11-26 00:26:10
问题 I have a base path /whatever/foo/ and $_GET[\'path\'] should be relative to it. However how do I accomplish this (reading the directory), without allowing directory traversal? eg. /\\.\\.|\\.\\./ Will not filter properly. 回答1: Well, one option would be to compare the real paths: $basepath = '/foo/bar/baz/'; $realBase = realpath($basepath); $userpath = $basepath . $_GET['path']; $realUserPath = realpath($userpath); if ($realUserPath === false || strpos($realUserPath, $realBase) !== 0) { /