Count of Files

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 6 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Count of Files

Post by apowershelluser »

So I'm trying to show the count of about 40 different folders
Desktop
Documents
MozillaProfiles
Outlook
etc...

My current working theory is

$folder = "C:\users\user\desktop"
$DesktopCount = Get-ChildItem $folder -Force -Recurse -File | Measure-Object | %{$_.Count}

Then at the end of the script I do
$DesktopCount+$DocumentsCount+$DownloadsCount+$FavoritesCount+$LinksCount

Is there a better way of doing this?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Count of Files

Post by jvierra »

It is not clear what you are tri ng to do.

$folders = 'desktop','documents', 'outlook' … etc

$count = (Get-Childitem $folders -File -Recurse).Count
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Count of Files

Post by apowershelluser »

I'm trying to provide the count of files of the folders I'm going to move through robocopy and display it to the technician
Then, once the robocopy job is done, I'm going to provide them the count on the new PC

The problem, is not all files are under the users profile so I can't just count that. They are spread throughout the PC so I have to do the individual counts.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Count of Files

Post by jvierra »

RoboCopy can count the files faster than PowerShell. Just select "log only" and extract the file count.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Count of Files

Post by apowershelluser »

$folders = "C:\users\user\desktop","C:\users\user\documents"
$count = $null
foreach ($folder in $folders){

$rclog = robocopy $folder \xxx /L /E
$count += ($rclog -match 'new File' ).Count

}

$count

Looks like a winner!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Count of Files

Post by jvierra »

Little trick...

Create a new folder. Symlink target folders into new folder. Run RoboCopy from new folder root and all can be copied/counted/moved in one command.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Count of Files

Post by apowershelluser »

Huh? lol

I'll give you some examples of the different folders I'm moving

"C:\users\$user\desktop"
"C:\Users\$user\AppData\Local\Google\Chrome\User Data\Default"
"C:\Users\$user\AppData\Local\Microsoft\Feeds"
"C:\Users\$user\AppData\Local\Microsoft\Internet Explorer\EmieUserList"
"C:\Users\$user\AppData\Roaming\Mozilla\Firefox"
"C:\Users\$user\AppData\Roaming\Microsoft\Outlook"
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Count of Files

Post by apowershelluser »

jvierra wrote: Thu Mar 14, 2019 1:05 pm Little trick...

Create a new folder. Symlink target folders into new folder. Run RoboCopy from new folder root and all can be copied/counted/moved in one command.
Getting back to this as it's a side project
SymLink.png
SymLink.png (19.46 KiB) Viewed 3933 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Count of Files

Post by jvierra »

You need to learn how to use symlinks and mklink.

You should not be doing this over the system folders.

Please don't post images of your code. Post code. The images do not tell us what you are doing.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Count of Files

Post by apowershelluser »

C:\link is considered a system folder?

I've researched a bit this morning and it doesn't look like you can symlink multiple folders to one
This topic is 5 years and 6 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked