Path error in script

8,257

Solution 1

Try this:

$files = Get-ChildItem "\\hilltop3\users$\LongRandy\My Documents\TIDBITS" -recurse | where{$_.mode -notlike "d*"}
$files | group-object -Property extension | sort count -Descending

Solution 2

Because your file path has a space in it, you need to wrap it in quotes so that PowerShell knows it's a single string/argument.

Notice in the error:

Cannot find path '\hilltop3\users$\LongRandy\My' because it does not exist.

It stops at the Space after My because spaces are used to distinguish between individual arguments in the command.

Try something like:

Get-ChildItem "\\hilltop3\users$\LongRandy\My Documents\TIDBITS"

Share:
8,257

Related videos on Youtube

DATAfiend
Author by

DATAfiend

Python autodidact and wisdom seeker.

Updated on September 18, 2022

Comments

  • DATAfiend
    DATAfiend over 1 year

    I am Googling scripts to find a PS script to count file types and files in several directory's on our network.

    I have several directory's on my "Libraries" directory on my PC at work.

    I'm just trying to test a PS script to get this to work to count the files and list the file types in my "Libraries\Documents\Tidbits" folder:

    Get-ChildItem \\hilltop3\users$\LongRandy\My Documents\TIDBITS

    but I get this error:

    Get-ChildItem : Cannot find path '\\hilltop3\users$\LongRandy\My' because it does not exist.
    At line:1 char:14
    + Get-ChildItem <<<< \\hilltop3\users$\LongRandy\My Documents\TIDBITS
    + CategoryInfo : ObjectNotFound: (\\hilltop3\users$\LongRandy\My:String) [Get-ChildItem], ItemNotFoundExc
    eption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand"
    

    Thanks again

  • DATAfiend
    DATAfiend about 9 years
    zoredache, It looks like megamorf's script worked. I'm still curious about the default name for "My Documents". Is this common to change My Documents to Documents or vice versa?
  • DATAfiend
    DATAfiend about 9 years
    It worked, many thanks. But, why do you have the "$files =" at the beginning of the line?
  • megamorf
    megamorf about 9 years
    That stores the result of the Get-Childitem in a variable. All variables in Powershell begin with $ sign. Storing a result of a long query in a variable allows you to filter, group, etc it without having to wait for Get-Childitem to return all of the files.