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.
Table of Contents
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:\
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
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”
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.
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
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.
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
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.