- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy files with the specific extension in PowerShell?
To copy the files with the specific extension, you need to use the Get-ChildItem command. Through the Get-ChildItem you first need to retrieve the files with the specific extension(s) and then you need to pipeline Copy-Item command.
Here, we need to copy *.txt files from the source to the destination location.
First, we will retrieve all the *.txt files available in the source path.
Example
Get-ChildItem D:\Temp\ -Filter *.txt
Output
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Filter *.txt Directory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 26-01-2020 19:20 13818 aliases.txt -a---- 18-01-2020 18:25 48 delim.txt -a---- 18-01-2020 17:25 14 GetContentExample.txt -a---- 17-01-2020 22:04 55190 Processes.txt -a---- 18-01-2020 18:22 27620 ReadC.txt -ar--- 13-01-2020 18:19 0 Readonlyfile.txt -a---- 18-01-2020 18:44 22 stream1.txt -a---- 18-01-2020 16:26 27620 testreadC.txt
We are going to copy the above files to the destination folder.
Example
Get-ChildItem D:\Temp\ -Filter *.txt | Copy-Item - Destination D:\TempContent\ -Force -PassThru
Output
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Filter *.txt | Copy-Item -Destination D:\TempContent\ -Force -PassThru Directory: D:\TempContent Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 26-01-2020 19:20 13818 aliases.txt -a---- 18-01-2020 18:25 48 delim.txt -a---- 18-01-2020 17:25 14 GetContentExample.txt -a---- 17-01-2020 22:04 55190 Processes.txt -a---- 18-01-2020 18:22 27620 ReadC.txt -ar--- 13-01-2020 18:19 0 Readonlyfile.txt -a---- 18-01-2020 18:44 22 stream1.txt -a---- 18-01-2020 16:26 27620 testreadC.txt
- Related Articles
- How to copy files of the specific extension using PowerShell?
- How to copy multiple files in PowerShell using Copy-Item?
- How to copy only updated or newer files with PowerShell?
- How to exclude specific extension in Get-ChildItem in PowerShell?
- Recursively Deleting Files With a Specific Extension on Linux
- How to copy files/folders to the remote location in the PowerShell?
- How to copy readonly and hidden files/folders in the PowerShell?
- How to use Get-ChildItem in PowerShell to filter a specific extension?
- How to search for a specific extension using Get-ChildItem in PowerShell?
- How to retrieve a specific number of lines from files in PowerShell?
- How to get the file extension using PowerShell?
- How to find all files in a directory with extension .txt in Python?
- How to copy folder contents in PowerShell with –Recurse parameter?
- How to copy Items to the destination path with the different\ncredentials in PowerShell?
- How to get the installed Azure VM extension using PowerShell?

Advertisements