PowerShell을 사용하여 파일에서 readonly 속성을 제거하는 방법은 무엇입니까?
-
23-08-2019 - |
문제
PowerShell (버전 1.0) 스크립트를 사용하여 파일에서 readonly 속성을 제거하려면 어떻게해야합니까?
해결책
당신이 사용할 수있는 Set-ItemProperty
:
Set-ItemProperty file.txt -name IsReadOnly -value $false
또는 짧은 :
sp file.txt IsReadOnly $false
다른 팁
$file = Get-Item "C:\Temp\Test.txt"
if ($file.attributes -band [system.IO.FileAttributes]::ReadOnly)
{
$file.attributes = $file.attributes -bxor [system.IO.FileAttributes]::ReadOnly
}
위의 코드 스 니펫은 이것에서 가져옵니다 기사
업데이트사용 키이스 힐 의견에서 구현 (이것을 테스트했으며 작동합니다). 이것은 다음과 같습니다.
$file = Get-Item "C:\Temp\Test.txt"
if ($file.IsReadOnly -eq $true)
{
$file.IsReadOnly = $false
}
그렇지 않더라도 토종의 PowerShell, 여전히 간단한 것을 사용할 수 있습니다 attrib 이것에 대한 명령 :
attrib -R file.txt
또는 간단히 사용할 수 있습니다.
get-childitem *.cs -Recurse -File | % { $_.IsReadOnly=$false }
위는 현재 폴더의 하위 트리의 모든 .CS 파일에 대해 작동합니다. 다른 유형이 포함되어 있으면 필요에 따라 "*.cs"를 조정하십시오.
당신이 사용하는 경우 PowerShell 커뮤니티 확장:
PS> Set-Writable test.txt
PS> dir . -r *.cs | Set-Writable
# Using alias swr
PS> dir . -r *.cs | swr
당신은 다음과 같이 반대 할 수 있습니다.
PS> dir . -r *.cs | Set-ReadOnly
# Using alias sro
PS> dir . -r *.cs | sro
Shell("net share sharefolder=c:\sharefolder/GRANT:Everyone,FULL")
Shell("net share sharefolder= c:\sharefolder/G:Everyone:F /SPEC B")
Shell("Icacls C:\sharefolder/grant Everyone:F /inheritance:e /T")
Shell("attrib -r +s C:\\sharefolder\*.* /s /d", AppWinStyle.Hide)
문제를 해결하는 데 도움을 주신 모든 분들께 감사드립니다 ...이 코드를 돕습니다.
이 코드는 저를 위해 작동합니다 .. 읽기 및 쓰기 권한을 가진 모든 폴더를 공유하려면 .NET 에서이 폴더를 사용할 수 있습니다.
제휴하지 않습니다 StackOverflow