PowerShell Newbie Question

Dear All,

Excuse my lack of experience. I am trying to generate a text file that includes all files that end with ‘*.txt’ from the whole HARD-DRIVE, using Mac

my command looks like the following:

Get-ChildItem -Path "./" -Recurse -Name -Include '*.txt' | Out-File "./Desktop/JUNK/HD-Files.txt"
It works very well and very fast but my problem is the '-recurse' commant which doesn't stop on my terminal I always end up stopping the command myself.

Anybody knows how I can solve that on the command-line itself?

 

I would appreciate the help!

 

Regards,

Mido

Recursion is going to look for files in every directory at every depth, so when you say it doesn’t stop, what exactly does that mean? 10 minutes, 2 hours? Are you seeing a file created with the file information?

The only thing that I would recommend is that you create a csv rather than a text file. Powershell will return an object, which is more of a table.

Get-ChildItem -Path “./” -Recurse -Name -Include ‘*.txt’ | Export-CSV “./Desktop/JUNK/HD-Files.csv” -NoTypeInformation

Hmmm … I do not have a Mac so I’m not able to reproduce but you might elaborate a little more what’s your problem.

If you start Get-ChildItem in the root and tell it to -Recurse it will only stop if it has searched each and evetry single folder on the drive. It might just take a little longer … did you try to wait a little longer?

[quote quote=204876]Hmmm … I do not have a Mac so I’m not able to reproduce but you might elaborate a little more what’s your problem.

If you start Get-ChildItem in the root and tell it to -Recurse it will only stop if it has searched each and evetry single folder on the drive. It might just take a little longer … did you try to wait a little longer?

[/quote]

[quote quote=204873]Recursion is going to look for files in every directory at every depth, so when you say it doesn’t stop, what exactly does that mean? 10 minutes, 2 hours? Are you seeing a file created with the file information?

The only thing that I would recommend is that you create a csv rather than a text file. Powershell will return an object, which is more of a table.

<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 7.2246875px; left: 45px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
Get-ChildItem -Path “./-Recurse -Name -Include*.txt| Export-CSV “./Desktop/JUNK/HD-Files.csv-NoTypeInformation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote]

I appreciate your reply! Indeed I got used to PS being fast even with large data, which is why I haven’t given it enough time apparently. But now after you suggested to do that, it actually worked and it stopped by itself.

 

Thank you very much!

Regards,

Mohamed.