File & Folder
파일과 폴더
get-childitem (= gci)
- 현재 폴더와 파일 리스트 형식으로 출력
get-childitem -force
- 숨겨진 폴더와 파일을 리스트 형식으로 출력
get-childitem -recurse
- 하위에 있는 폴더와 파일을 리스트 형식으로 출력
get-childitem -path "c:\program files" -recurse -include * .exe
- -path : 경로
- -include :지정한 형식을 포함한 모든 폴더와 파일 출력
cd
- 폴더 이동
copy-item
- 파일, 폴더 복사
- copy-itrm -path c:\candy.txt -destination c:\apple
->candy.txt 파일을 apple 폴더에 복사
- copy-itrm -path c:\banana -destination c:\apple
-> banana 폴더를 apple 폴더에 복사
move-item
- 파일, 폴더 이동
- move-itrm -path c:\candy.txt -destination c:\apple
- move-itrm -path c:\banana -destination c:\apple
remove-item
- 파일, 폴더 삭제
- remove-item -path c:\apple
파일과 폴더 읽기 & 쓰기
new-item
new-item -path "c:\apple" -itemtype directory
-> apple 폴더 생성
new-item -path "c:\file.txt" -itemtype file
-> file.txt 파일 생성
set-content
set-content c:\file.txt "Hello PowerShell"
-> Hello PowerShell 입력됨
set-content c:\file.txt "Hello Window"
-> Hello PowerShell 은 사라지고 Hello Window가 입력됨
add-content
add-content c:\file.txt "Nice Day"
-> 원래 있던 내용 뒤에 내용 추가
파일을 생성하는 다른방법
get-childitem | out-file c:\folderlist.txt
- get-childitem 에 있는 내용을 folderlist.txt 파일로 내용 출력
get-content
- 파일을 읽는 명령어
- get-content c:\folderlist.txt
html로 파일 출력
get-service | convertTo-HTML name, displayname, status | Set-content c:\\svc.html
xml로 파일 출력
get-childitem |export-clixml c:\XMLtest.xml
csv로 파일 출력
get-service | export-CSV "c:\svcList.csv"
csv를 읽는 명령어
import-csv c:\svclist.csv
윈도우에 설치된 csv에 연결된 프로그램이 실행되며 파일 열림
invoke-item c:\svclist.csv