PowerShell: Use Get-ChildItem to Get Full Path of Files


You can use the following syntax in PowerShell to use the Get-ChildItem cmdlet to get the full path of files in a particular folder:

(Get-ChildItem c:\users\bobbi\current_data -Recurse).FullName

This particular example will get the full path of each file located in the following folder:

  • c:\users\bobbi\current_data

By using the FullName property, we are able to get the full path of each file.

The following example shows how to use this syntax in practice.

Example: Use Get-ChildItem to Get Full Path of Files in PowerShell

Suppose we have a folder named current_data saved in the following location:

  • c:\users\bobbi\current_data

We can use the following syntax to view each of the files in this folder:

$path = "c:\users\bobbi\current_data"
Dir $path

The following screenshot shows how to use this syntax in practice:

We can see that the folder contains the following five Excel files:

  • baseball_data.xlsx
  • basketball_data.xlsx
  • football_data.xlsx
  • hockey_data.xlsx
  • new_hockey_data.xlsx

Notice that these file names don’t contain the full path.

If we would like to view the full path for each of these files, we can use the following syntax to do so:

(Get-ChildItem c:\users\bobbi\current_data -Recurse).FullName

The following screenshot shows how to use this syntax in practice:

PowerShell Get-ChildItem get full path

Notice that the full path of each file in the folder is now shown:

  • c:\users\bobbi\current_data\baseball_data.xlsx
  • c:\users\bobbi\current_data\basketball_data.xlsx
  • c:\users\bobbi\current_data\football_data.xlsx
  • c:\users\bobbi\current_data\hockey_data.xlsx
  • c:\users\bobbi\current_data\new_hockey_data.xlsx

If we’d like, we can use the following syntax to export each of these full paths to a text file:

(Get-ChildItem c:\users\bobbi\current_data -Recurse).FullName > full_names.txt

The following screenshot shows how to use this syntax in practice:

We can then navigate to where this text file is located on our computer to view it:

We can see that the text file contains the full path of each file in the folder.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Use Get-ChildItem with Filter
PowerShell: How to Create Array from CSV File
PowerShell: How to Compare Two Files

Leave a Reply