Yuav ua li cas rau tsim ib tug tshiab cov ntaub ntawv nyob rau hauv PowerShell?
tshiab-yam lo lus tseem ceeb tsim cov ntaub ntawv tshiab hauv cov ntaub ntawv. The type of item new item creates depends on where the item is being created. Piv txwv li, yam khoom tshiab kuj yuav tsim npe lag luam thiab nkag yog siv nyob rau hauv lub npe.
Type the following command in to create a new file in the current path:
ni {filename.extension}
The above is the alias for the following command…
tshiab-yam khoom {filename.extension}
Piv txwv li
ni fun.txt
Tsis muaj peev xwm kuj yuav siv tau nrog yam khoom tshiab.
Cov nram qab no tsim ib cov ntaub ntawv nyob rau hauv lub tam sim no txoj kev nrog ib co ntsiab lus:
ni -n fun.txt -p . -it f -v 'this is some silly text'
In the above example we have added the -name, -path and -itemtype parameters with their default values. Omitting these will generate the same result.
ni fun.txt -v 'this is some silly text'
If you want to overwrite an existing file use the -force or -f parameter:
ni fun.txt -v 'this is some silly text' -f
Tsim ntau yam ntaub ntawv nyob rau hauv lub tam sim no directory:
ni -it f -p 'file.txt', 'fun.txt'
Tsim ntau yam ntaub ntawv nyob rau hauv lub c:/ hauv paus thiab tej yam uas directory
ni -it f -p 'c:\file.txt', 'c:\things\fun.txt'
tsim txoj kev
You can create a new directory instead of mkdir or md by using the new item command and setting the item type as directory.
ni fun -it d
Tsim ib tug tshiab directory nyob rau hauv lub c hauv paus:
ni -n fun -it d -p c:\
Tsim ntau yam Wage nyob rau hauv lub tam sim no txoj kev:
ni -it d -p 'fun', 'silly'
Tsim ntau yam Wage nyob rau hauv lub c:/ hauv paus thiab tej yam uas directory
ni -it d -p 'c:\folder', 'c:\things\fun'
The following table shows the parameters and it’s alias
| Parameter | cai | Piv txwv li | Hauj lwm |
-name
|
-n or no parameter |
ni fun.txt
|
Specify the new item’s name |
-itemtype
|
-it
|
-it d los yog -it dir los yog -it directory-it f los yog -it file |
Specify the type of item to create. Creates file by default. |
-force
|
-f |
-f |
Overwrite existing file. |
-value
|
-v
|
-v 'Some file content...'
|
Write content of file |
-path
|
-p
|
-p c:\
|
Path of where the new item should be created |
Some commands that is useful with the ni command:
ls – Get-ChildItem, lists files and directories of the current working directory. piv txwv li ls
gc – Get-Content, view the contents of a file eg. gc fun.txt
md – mkdir, make directory eg. md mynewdirectory
rm– Remove-Item, remove directory or file

Conteúdo top de mais, parabéns!