Files
PowerShell/docs/touch.md
Markus Fleschutz d8690419ea Updated the manuals
2025-06-22 10:38:33 +02:00

75 lines
1.6 KiB
Markdown

The *touch.ps1* Script
===========================
This PowerShell script creates a new empty file.
Parameters
----------
```powershell
/Repos/PowerShell/scripts/touch.ps1 [[-filename] <String>] [<CommonParameters>]
-filename <String>
Path and filename of the new file
Required? false
Position? 1
Default value
Accept pipeline input? false
Aliases
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
Example
-------
```powershell
PS> ./touch.ps1 test.txt
Created a new empty file called 'test.txt'.
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.SYNOPSIS
Create an empty file
.DESCRIPTION
This PowerShell script creates a new empty file.
.PARAMETER filename
Path and filename of the new file
.EXAMPLE
PS> ./touch.ps1 test.txt
✅ Created a new empty file called 'test.txt'.
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$filename = "")
try {
if ($filename -eq "") { $filename = Read-Host "Enter the filename" }
"" | Out-File $filename -encoding ASCII
"✅ Created a new empty file called '$filename'."
exit 0 # success
} catch {
"⚠️ Error: $($Error[0])"
exit 1
}
```
*(page generated by convert-ps2md.ps1 as of 06/22/2025 10:37:41)*