Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1dea611

Browse filesBrowse files
Create mkfile.ps1
1 parent c7124bc commit 1dea611
Copy full SHA for 1dea611

File tree

Expand file treeCollapse file tree

1 file changed

+107
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+107
-0
lines changed

‎mkfile.ps1

Copy file name to clipboard
+107Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Makefile
2+
82 │ function mkfile {
3+
83<#
4+
84 │ .SYNOPSIS
5+
85 │ Creates one or more files in the specified paths.
6+
86 │
7+
87 │ .DESCRIPTION
8+
88 │ The mkfile function creates one or more files in the specified paths. If a directory does not exist, it will b
9+
│ e created automatically. The function supports options for displaying version information and additional detai
10+
│ ls about the function itself.
11+
89 │
12+
90 │ .PARAMETER FilePaths
13+
91 │ Specifies the path(s) of the file(s) to be created. Wildcard characters are permitted. This parameter is manda
14+
│ tory if the -Version or -Info parameters are not specified.
15+
92 │
16+
93 │ .PARAMETER Version
17+
94 │ Displays the version information for the mkfile function.
18+
95 │
19+
96 │ .PARAMETER Info
20+
97 │ Displays additional information about the mkfile function, including its description, repository URL, and auth
21+
│ or.
22+
98 │
23+
99 │ .INPUTS
24+
100 │ System.String[]
25+
101 │ The mkfile function accepts one or more file paths as input.
26+
102 │
27+
103 │ .OUTPUTS
28+
104 │ None
29+
105 │ The mkfile function does not generate any output objects.
30+
106 │
31+
107 │ .EXAMPLE
32+
108 │ mkfile test.txt
33+
109 │ Creates a file named 'test.txt' in the current directory.
34+
110 │
35+
111 │ .EXAMPLE
36+
112 │ mkfile C:\Temp\file1.txt C:\Temp\file2.txt
37+
113 │ Creates two files, 'file1.txt' and 'file2.txt', in the 'C:\Temp' directory.
38+
114 │
39+
115 │ .EXAMPLE
40+
116 │ mkfile -Version
41+
117 │ Displays the version information for the mkfile function.
42+
118 │
43+
119 │ .EXAMPLE
44+
120 │ mkfile -Info
45+
121 │ Displays additional information about the mkfile function.
46+
122 │
47+
123 │ .NOTES
48+
124 │ Author: thecodermehedi
49+
125 │ Repository: https://github.com/thecodermehedi/mkfile-powershell
50+
126 │ Version: v1.0.0
51+
127 │
52+
128 │ .LINK
53+
129 │ https://github.com/thecodermehedi/mkfile-powershell
54+
130 │ #>
55+
131 │ [CmdletBinding()]
56+
132param(
57+
133 │ [Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
58+
134 │ [Alias('FullName')]
59+
135 │ [string[]]$FilePaths,
60+
136
61+
137 │ [Parameter(Mandatory=$false)]
62+
138 │ [Alias('v')]
63+
139 │ [switch]$Version,
64+
140
65+
141 │ [Parameter(Mandatory=$false)]
66+
142 │ [Alias('i')]
67+
143 │ [switch]$Info
68+
144 │ )
69+
145
70+
146if ($Version) {
71+
147Write-Host "v1.0.0"
72+
148return
73+
149 │ }
74+
150
75+
151if ($Info) {
76+
152Write-Host "mkfile: A PowerShell function to create files."
77+
153Write-Host "Repository: https://github.com/thecodermehedi/mkfile-powershell"
78+
154Write-Host "Author: thecodermehedi"
79+
155Write-Host "Version: v1.0.0"
80+
156return
81+
157 │ }
82+
158
83+
159if (-not $FilePaths -or $FilePaths.Count -eq 0) {
84+
160Write-Host "Usage: mkfile [-?] [-v] [-i] <file_path> [<file_path>...]"
85+
161return
86+
162 │ }
87+
163
88+
164process {
89+
165foreach ($FilePath in $FilePaths) {
90+
166try {
91+
167$FileDir = Split-Path -Path $FilePath -Parent
92+
168$FileName = Split-Path -Path $FilePath -Leaf
93+
169
94+
170if (-not (Test-Path -Path $FileDir)) {
95+
171$null = New-Item -Path $FileDir -ItemType Directory -Force
96+
172 │ }
97+
173
98+
174$null = New-Item -Path $FilePath -ItemType File -Force
99+
175
100+
176Write-Host "File '$FileName' created successfully."
101+
177 │ }
102+
178catch {
103+
179Write-Host "Error: $_" -ForegroundColor Red
104+
180 │ }
105+
181 │ }
106+
182 │ }
107+
183 │ }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.