Getting tree structure of directories
By : Vijay P Singh
Date : March 29 2020, 07:55 AM
it fixes the issue level = root.replace(startpath, '').count(os.sep) It's calculating level of indentation for printing object (dir/file) name. It's getting rid of startpath as it's common for every listed file and it would look bad to have everything indented by +10 tabs :) os.sep returns path separator like '/' on Linux.
|
How to find in a directory tree directories containing from 2 to 3 subdirectories?
By : Deborah Caulet
Date : March 29 2020, 07:55 AM
it should still fix some issue In a given directory tree i want to search directories containing from 2 to 3 subdirectories code :
find . -type d -printf "%p " -exec find {} \
-maxdepth 1 -type d -printf "x" \; -printf "\n" | egrep ' x{2,3}$'
|
List directories and files in a tree structure
By : Aaron
Date : March 29 2020, 07:55 AM
Any of those help If you don't have tree you can use GNU find to identify directories vs files: code :
$ find . -mindepth 1 -printf '%y %p\n'
d ./dir1
d ./dir1/dir2
f ./dir1/dir2/fileA
d ./dir1/dir3
f ./dir1/fileC
f ./fileB
$ find . -mindepth 1 -printf '%y %p\n' |
awk '$1=="d"{sub(/.*\//,"&DIR: ")} {gsub(/[^\/]*\//," ")} 1'
DIR: dir1
DIR: dir2
fileA
DIR: dir3
fileC
fileB
|
Loop through tree structure of directories in Azure
By : Getaji
Date : March 29 2020, 07:55 AM
With these it helps I have the exact same directory structure with an additional folder for each hour in the day. I process each blob in each folder and 'clean' them. Some pseudo code
|
Shell - copying directories recursively with RegEx matching preserving tree structure
By : Tanya
Date : March 29 2020, 07:55 AM
I wish this help you I need to write a script, that would copy a directory recursively, but only copying subdirectories and files matched by a certain RegEx. For instance for a tree like this: , You can do that using find command and loop through the results: code :
#!/usr/bin/env bash
cd toDir
while IFS= read -rd '' elem; do
if [[ -d $elem ]]; then
mkdir -p ../newDir/"$elem"
else
d="${elem%/*}"
mkdir -p ../newDir/"$d"
cp "$elem" ../newDir/"$d"
fi
done < <(find . -name '*[0-9]*' -print0)
|