Windows API 코드 팩을 사용하여 파일 확장 속성을 설정/편집할 수 있습니까?
-
21-12-2019 - |
문제
파일 확장 속성을 설정/편집할 수 있는지 알고 싶습니다(탐색기:Windows API 코드 팩을 사용하여 마우스 오른쪽 버튼 클릭 > 속성 > 세부 정보)를 클릭합니다.
var shellFile = Microsoft.WindowsAPICodePack.Shell.ShellObject.FromParsingName(filePath);
var artistName = shellFile.Properties.GetProperty(SystemProperties.System.Music.DisplayArtist).ValueAsObject.ToString();
var duration = TimeSpan.FromMilliseconds(Convert.ToDouble(shellFile.Properties.GetProperty(SystemProperties.System.Media.Duration).ValueAsObject) * 0.0001);
이 몇 줄을 사용하여 원하는 속성을 얻었지만 그 중 하나(예: 아티스트 이름)를 편집하는 방법을 모르겠습니다.taglib-sharp를 사용할 수 있다는 것을 알고 있지만 외부 코드가 없는 솔루션이 없는 경우에만 사용하겠습니다.
시간을 내어 도와주신 모든 분들께 감사드립니다.
해결책
ShellPropertyWriter
로 일부 속성을 편집하는 방법을 찾았지만 일부 속성은 읽기 전용입니다.
var shellFile = ShellFile.FromParsingName(filePath);
ShellPropertyWriter w = shellFile.Properties.GetPropertyWriter();
try
{
w.WriteProperty(SystemProperties.System.Author, new string[] { "MyTest", "Test" });
w.WriteProperty(SystemProperties.System.Music.Artist, new string[] { "MyTest", "Test" });
w.WriteProperty(SystemProperties.System.Music.DisplayArtist, "Test");
}
catch (Exception ex)
{
}
w.Close();
.
이 샘플에서는 ShellPropertyWriter.WriteProperty()
의 첫 번째 발생을 똑같이 동일하게 수행하고 파일의 "기여한 예술가"필드를 편집합니다 (탐색기 : 마우스 오른쪽 버튼> 속성> 세부 정보).세 번째 호출은 "액세스가 거부 된"예외를 throw합니다.
일부는 편집 가능하고 다른 사람들은 그렇지 않습니다.그냥 시도해야합니다.
다른 팁
당신은에 쓸 수 있습니다 ShellFile
없이 속성 값을 설정하여 직접 ShellPropertyWriter
:
var shellFile = ShellFile.FromFilePath(filePath);
shellFile.Properties.System.Author.Value = new string[] { "MyTest", "Test" };
shellFile.Properties.System.Music.Artist.Value = new string[] { "MyTest", "Test" };
shellFile.Properties.System.Music.DisplayArtist.Value = "Test";
파일의 코덱별 필드를 편집하려면 컴퓨터에 코덱이 설치되어 있어야 합니다.
제휴하지 않습니다 StackOverflow