Advance

How to Manage Files And Folders In PowerShell

How to Manage Files And Folders In PowerShell
1
(1)

In this article from the PowerShell tutorial series, we will teach you how to manage files and folders in PowerShell. By using Windows PowerShell, you can manage files and folders on your computer. It is very helpful for Windows System Admins who frequently work with the file systems to perform tasks. These tasks include create, copy, rename, and delete files and folders.

You can also buy and use the Windows VPS Server from eldernode.

Recommended Article: How to convert Windows Core to Windows Server

1. List all files in one folder

You can use the Get-ChildItem command to list all items in a folder. Consider the following example:

 PS C:\ > Get-ChildItem -Force C:\  

 

manage files and folders in powershell-0

 

2. List all items, including hidden files and services

Using the following command, all files are placed in a folder:

 PS C:\> Get-ChildItem -Force C:\ -Recurse  

 

manage files and folders in powershell-1

 

3. Create Folders

You can create new folders in PowerShell using the following command. To Create a folder, specify the -ItemType as directory.

Note that in the following command, I specified my folder location as C: \Rakesh\New Folder.

 PS C:\> New-Item -Path ‘C:\Rakesh\New Folder’ -ItemType “directory”  

 

manage files and folders in powershell-2

 

4. Create an empty text file

Use the following command to create an empty text file:

 PS C:\> New-Item -Path ‘C:\Rakesh\New Folder    \file.txt’ -ItemType “file”  

You must specify the -ItemType as file to create an empty file. If you want to create a folder, then the -ItemType should be directory.

 

manage files and folders in powershell-3

 

5. Copy File and Folders

To copy a file from one location to another, you must specify the source and destination as instructed below.

 PS C:\> Copy-Item -Path C:\Rakesh -Destination C:\Vemulawada  

 

manage files and folders in powershell-4

6. Rename a file or folder

To rename a file or folder, use the following command:

 PS C:\> Remove-Item C:\file3 File4.txt  

In this example, the file3 name is changed to file4.

 

manage files and folders in powershell-5

 

7. Delete File or Folder

Using the following command, you can specify the path of the item you want to delete so that you can delete it.

 PS C:\> Remove-Item C:\Rakesh  

 

manage files and folders in powershell-6

 

Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problem in it as soon as possible. Make time for other users and experts to answer your questions.

Goodluck.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day