# Script to Create Files and Folders on Windows devices

It is simple to create a file or folder on a device. However, creating files and folders on a large number of devices in a specified location becomes a time-consuming task. Hence, you can simplify this process on Windows devices by [deploying custom scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) from Hexnode.

 Note: 
**Supported Versions**:

The scripts given below will be supported on the following versions:

- Windows 10 v1607+ (Pro, Enterprise, Education)
- Windows 11 (Pro, Enterprise, Education)

[ ](https://developer.android.com/develop/connectivity/uwb#uwb-enabled_mobile_devices)

 

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

Create Files
------------

### Batch Script

Batch script to create a file

@echo off echo "Hello">C:\\filename.txt 

   1

2

  @echo off 

echo "Hello">C:\\filename.txt 

   

 

  

**Create a file after checking whether it already exists**

Batch script to create a file after checking whether it already exists

@echo off Cd “Location where the file needs to be created” If exist filename.ext ( Echo “A file with this name already exists” )else ( Type nul>filename.ext Echo “File has been created” ) 

   1

2

3

4

5

6

7

8

  @echo off 

Cd “Location where the file needs to be created”

If exist filename.ext (

Echo “A file with this name already exists”

)else (

Type nul>filename.ext 

Echo “File has been created”

) 

   

 

  

Replace ‘`filename`‘ with a file name of your choice and make sure the file extension is the same throughout the script. Provide the path where you want the file to be created.

###  PowerShell Script 

PowerShell script to create a file

New-Item D:\\temp\\test\\pc.txt 

   1

  New-Item D:\\temp\\test\\pc.txt 

   

 

  

**Create a file after checking whether it already exists**

PowerShell script to create a file after checking whether it already exists

\#create array of text files $files=Get-ChildItem C:\\data\\\*.txt | select -expand fullname #check if file exists inside the array $files -match "pc.txt" if($files -match "pc.txt") { Write-Host “File Exists” } else { New-Item C:\\data\\pc.txt } 

   1

2

3

4

5

6

7

8

9

10

  \#create array of text files 

$files=Get-ChildItem C:\\data\\\*.txt | select -expand fullname

\#check if file exists inside the array $files -match "pc.txt" 

if($files -match "pc.txt")

{

Write-Host “File Exists”

}

 else {

New-Item C:\\data\\pc.txt

} 

   

 

  

Replace ‘`pc`‘ with a file name of your choice and make sure the file extension is the same throughout the script. Provide the path where you want the file to be created.

Create Folders
--------------

### Batch Script

Batch script to create a folder

md C:\\test 

   1

  md C:\\test 

   

 

  

### PowerShell Script

PowerShell script to create a folder

New-Item -Path "C:\\" -Name "test" -ItemType "directory"

   1

  New-Item -Path "C:\\" -Name "test" -ItemType "directory"

   

 

  

Replace ‘`test`’ with a folder name of your choice and provide the path where you want the folder to be created.

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.