특정 파일 특성을 선택할 수 있다고 가정 할 때이 코드가 있지만 어떤 이유로 인해 실제로 이상하게 작동합니다. 누구든지 오류를 발견 할 수 있습니까?파일 특성 선택 오류
이것은 형식입니다. 파일을 선택하면 checkAttributes가 트리거됩니다. (string) path는 선택된 파일의 경로입니다.
private async void Dropdown_File_Attr_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
try
{
foreach (FileAttributes attr in Enum.GetValues(typeof(FileAttributes)))
if (e.ClickedItem.Text == attr.ToString() && !(bool)e.ClickedItem.Tag)
File.SetAttributes(path, File.GetAttributes(path) | attr);
else if (e.ClickedItem.Text == attr.ToString() && (bool)e.ClickedItem.Tag)
File.SetAttributes(path, File.GetAttributes(path) & ~attr);
checkAttributes(path);
await WaitX(5);
Dropdown_File.ShowDropDown();
Dropdown_File_Attr.ShowDropDown();
}
catch (Exception ex) { MessageBox.Show("An error occured:\n\n" + ex.ToString(), "Error"); }
}
public async Task WaitX(int miliseconds) { await Task.Delay(miliseconds); }
private List<string> getAttributes(string ppath)
{
List<string> result = new List<string>();
FileAttributes attrs = File.GetAttributes(ppath);
if ((attrs & FileAttributes.Archive) == FileAttributes.Archive) result.Add("Archive");
if ((attrs & FileAttributes.Compressed) == FileAttributes.Compressed) result.Add("Compressed");
// This goes on for every attribute
return result;
}
private void checkAttributes(string ppath)
{
foreach (string s in getAttributes(ppath))
foreach (ToolStripDropDownItem item in Dropdown_File_Attr.DropDownItems)
{
if (item.Text == s)
{
item.Image = Resources.check;
item.Tag = true; // isChecked
}
else
{
item.Image = Resources.cross;
item.Tag = false; // isChecked
}
}
}
그냥 예 :
선택, 나는 숨겨진 선택 처음에만 보통의 경우, 숨겨진 십자가 유일합니다. ReadOnly를 선택하면 ReadOnly가 십자가가있는 유일한 파일이지만 확인하면 파일이 Windows 탐색기에 여전히 숨겨져 있습니다.
나는 오류 시간을 찾고 있었다. 누구든지 나를 도와주세요 (Enums 및 FileAttributes에 대한 많은 경험이 없습니다)?
제목을 편집했습니다. "[제목에"태그 "가 포함되어 있어야합니까?] (http://meta.stackexchange.com/questions/19190/)"합의가 "아니오, 그렇지 않아야한다"는 것을 참조하십시오. –
오, 죄송합니다. 여기 새로 왔어요 – thijmen321
문제 없습니다. 다른 회원이 귀하의 게시물을 편집하게하는 것이 다른 사이트와 다른 점 중 하나입니다. 좋은 방법으로. –