![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Vista Home Premium 32bit | count number of files Hi guys. I need your help because I'm not able to solve a problem. Let's suppose I have a folder like this folder1 folder2 ... folderN file1 file2 ... fileN I want to count the number of files inside my folders, that is the total of files of folder1+folder2+folderN without counting file1,file2 and so on. Thanks in advance. |
My System Specs![]() |
| | #2 (permalink) |
| Vista Home Premium 32bit | Re: count number of files I've solved on my own. $folders = gci | ? {-$_.psiscontainer} $tot=0;foreach($folder in $folders) {$tot = $tot +(gci $folder).count} $tot I'm a newbie but I love powershell. Thanks the same. Have a nice day. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: count number of files Hi sardinian_guy, Glad you could resolve it yourself. I would like to add one thing, one Powershell gotcha to be aware of: In PowerShell, if your command results in one object only (scalar) then there is no count property available. Therefor, trying to count a directory that has only one child item will yield nothing. To make the result (any result) have a count property, force it to array @(), as in: @(gci $folder).count That's a very important rule of thumb, remember it ![]() BTW, if you want your command to include hidden files too, add the -force parameter to gci. --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com s> I've solved on my own. s> s> $folders = gci | ? {-$_.psiscontainer} s> $tot=0;foreach($folder in $folders) {$tot = $tot +(gci s> $folder).count} s> $tot s> I'm a newbie but I love powershell. Thanks the same. Have a nice day. s> ![]() s> |
My System Specs![]() |
| | #4 (permalink) |
| Vista Home Premium 32bit | Re: count number of files Hi Shay. ![]() I didn't know this thing. I created a folder with just one file within and indeed it doesn't give me any result. If I add another file it returns correctly two. Thank you very much for this trick and for all your useful posts. I'm learning a lot of interesting things reading you and other great users of this forum. Thanks again and sorry for my english. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Count number of times a box is ticked in Access 2003 | Microsoft Office | |||
| Re: how to count number of certain char within string | PowerShell | |||
| number of files in music folder | Vista music pictures video | |||
| Count the number of Columns/rows in a CSV file.... | PowerShell | |||