Answer the question
In order to leave comments, you need to log in
How to teach bash script and powershell to navigate recursively through directories?
Greetings!
There is a multi-level directory system, it is necessary that the script recursively go through them, and execute:
идём в первый каталог
if [ -d folder_name ] ; then
выполняем нужное действие
else
идём в следующий каталог
Answer the question
In order to leave comments, you need to log in
*nix has such an amazing tool as: find.
She can recursively go through directories and in general over all disks, well, and perform any actions at the same time.
Here is an example from the help:find /path -type d -exec chmod 0755 {} \;
I would write my recursive traversal as a function:
function doRecursiveThings ($path)
{
$childs = Get-ChildItem $path
foreach($child in $childs)
{
#Что-то делаем если надо делать для каждого элемента
if( [System.IO.File]::GetAttributes($child.FullName) -eq [System.IO.FileAttributes]::Directory )
{
#Или тут что-то делаем, если нужно сделать что-то в случае захода в каталог
doRecursiveThings ($child.FullName)
}
}
}
$path = "Путь к каталогу"
doRecursiveThings $path
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question