M
M
m00nkey2014-10-09 13:28:25
PowerShell
m00nkey, 2014-10-09 13:28:25

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
    идём в следующий каталог

How should it look?
Yes, there are such moments in the names of directories:
"name - folder & dir"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2014-10-09
@bk0011m

*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 {} \;

F
FlyingBrick, 2014-10-20
@FlyingBrick

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

A
Alexander Ruchkin, 2014-10-09
@VoidEx

ls -dir -r
does not fit in PowerShell?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question