private void Scan_files_Click(object sender, EventArgs e)
{
for (int i = 0; i < listView1.Items.Count; i++)
{
string filePath = Convert.ToString(listView1.Items[i]);
// MessageBox.Show("Files found: " + filePath, "Message");
// FileAttributes fileAttributes = File.GetAttributes(filePath);
if (((File.GetAttributes(filePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) && ((File.GetAttributes(filePath) & FileAttributes.Hidden) == FileAttributes.Hidden) && ((File.GetAttributes(filePath) & FileAttributes.System) == FileAttributes.System))
{
MessageBox.Show("File's Attributes: " + File.GetAttributes(filePath));
}
else
MessageBox.Show(" NO matching attrbutes");
}
}
我无法解决这个问题:S
答案 0 :(得分:2)
您可以使用这段代码查看文件属性:
for (int i = 0; i < listView1.Items.Count; i++)
{
string filePath = Convert.ToString(listView1.Items[i]);
if (!File.Exists(filePath))
return;
//make sure you have a correct file path in filePath variable
// check whether a file is read only
bool isReadOnly = ((File.GetAttributes(filePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly);
// check whether a file is hidden
bool isHidden = ((File.GetAttributes(filePath) & FileAttributes.Hidden) == FileAttributes.Hidden);
// check whether a file is system file
bool isSystem = ((File.GetAttributes(filePath) & FileAttributes.System) == FileAttributes.System);
if (isReadOnly || isHidden || isSystem)
MessageBox.Show("File's Attributes: " + File.GetAttributes(filePath));
else
MessageBox.Show("No. matching attrbutes");
}
快乐编码......
答案 1 :(得分:0)
调查您实际获得的filePath
,可以使用断点,或在调用File.GetAttributes之前,尝试:
if (!File.Exists(filePath))
{
MessageBox.Show(String.Format("File {0} not found.", filePath));
}