Copy files from folders which contain less than a number of files

0

Coming from Bash: Find folders with less than x files

find . -type d -exec sh -c 'set -- "$0"/*.flac; ! [ -e "$1" ]' {} \; -print

How do I extend the line to now recurse through the resulting list of folders, list the files and move/copy the files to somewhere else.

foax

Posted 2019-02-13T10:32:18.600

Reputation: 38

Answers

0

couldn't find help with linux or too dumb, so i used powershell

# list directories and number of files within each directory 
# and copy them away dependent on number of files
$dirs = gci -directory
foreach ($dir in $dirs) {
   $nof = (gci -file $dir | measure-object).count
   write-host $dir has $nof files
   if ($nof -le 4){
    copy-item .\$dir\*.* -destination h:\testdir   
    write-host files will be copied
    }
    else {
     write-host files will not be copied
    }
}

foax

Posted 2019-02-13T10:32:18.600

Reputation: 38