- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 of the specific extension using PowerShell?
To copy the files using the specific files extension using PowerShell, we can use the Copy-Item command.
The below command will copy only the .ps1 files from the source to the destination.
PS C:\> Copy-Item -Path C:\Temp -Recurse -Filter *.ps1 -Destination C:\Temp1\ -Verbose
If the C:\Temp1 doesn't exist, it will create the destination folder and then copy the content of the file but the problem with this command is it copies the subfolders as well which doesn’t have the .ps1 file.
So to copy the with the same folder structure without empty directories and the specific file extension we can write the code to check the size of the directory after copy and delete if the folder is empty but this would be a lengthy process.
We can use the xCopy or the RoboCopy command to overcome the above problem.
PS C:\> robocopy c:\temp c:\temp1 "*.ps1" /s
The above command will copy files with extension .ps1 from the C:\temp to the C:\temp1 without the empty folders.
- How to copy files with the specific extension in PowerShell?
- How to copy multiple files in PowerShell using Copy-Item?
- How to get the file extension using PowerShell?
- How to search for a specific extension using Get-ChildItem in PowerShell?
- How to exclude specific extension in Get-ChildItem in PowerShell?
- 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 copy only updated or newer files with PowerShell?
- How to get the installed Azure VM extension using PowerShell?
- How to use Get-ChildItem in PowerShell to filter a specific extension?
- How to Copy NTFS permissions using PowerShell?
- How to retrieve a specific number of lines from files in PowerShell?
- How to delete the specific tag of Azure VM using PowerShell?
- How to update the specific node of the XML file using PowerShell?
- How to start the specific task of the task scheduler using PowerShell?