-3

new-item -type file NAME/init.py

I have folder "NAME". The command "new-item" doesn't work. What should I do?

  • This is basic PS file system stuff. You have to remember items that have special meaning/defaults in PowerShell. Not properly quoting, not using PowerShell default names, switches, special characters, for what they are not meant for. Simple strings (path, filenames, values, so on...) should have single quotes and strings that require variable expansion or special formatting, requires double quotes. Periods mean current directory, run this code (if associated with a script block), or used for dot-sourcing properteies. Etc.. Serach fo rPowerShell special characters, varaibles, et all. – postanote Apr 19 '21 at 03:55

2 Answers2

1

You should try : New-Item -Path .\NAME -Name init.py -Type file

Use only the dot if you are located in your directory NAME, or enter the path (from the above directory or the full path).

ps: having the error output of powershell could be nice too.

Itchydon
  • 2,572
  • 6
  • 19
  • 33
ArmaTh
  • 49
  • 4
0

This...

new-item -type file NAME/init.py

... is simply not valid syntax. See the PowerShell help files for details on the cmdlet and use. Be specific, don't guess or force PowerShell to guess for you.

For Example:

Get-ChildItem -Path 'D:/Temp' -Filter 'init.py'
# Results
<#
No results
#>

New-Item -Path 'D:\Temp' -Name 'init.py' -ItemType file -WhatIf
# Results
<#
What if: Performing the operation "Create File" on target "Destination: D:\Temp\init.py".
#>

New-Item -Path 'D:\Temp' -Name 'init.py' -ItemType file
# Results
<#
    Directory: D:\Temp


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         18-Apr-21     20:45              0 init.py
#>

(Get-ChildItem -Path 'D:/Temp' -Filter 'init.py').FullName
# Results
<#
D:\Temp\init.py
#>


# Get specifics for a module, cmdlet, or function
(Get-Command -Name New-Item).Parameters
(Get-Command -Name New-Item).Parameters.Keys
Get-help -Name New-Item -Examples
# Results
<#
 New-Item -Path .\TestFolder -ItemType Directory
 New-Item -Path .\TestFolder\TestFile.txt -ItemType File
 New-Item -Path .\TestFolder -ItemType Directory -Force
 Get-ChildItem .\TestFolder\
 New-Item ./TestFile.txt -ItemType File -Value 'This is just a test file'

#>
Get-Help -Name New-Item -Detailed
Get-help -Name New-Item -Full
Get-help -Name New-Item -Online
postanote
  • 15,138
  • 2
  • 14
  • 25