Witam!
Mam mały problem. Potrzebuję zmienić nazwę katalogów Settings i Programs znajdujących się w Menu Start PocketPC. Oba te foldery nie pozwalają na zmianę nazwy, bo pisze że są Read Only. Zatem przy funkcji rename dodałem zdjęcie flagi ReadOnly i ustawienie tego, na dodatek robię dodatkowo ustawienie flagi normal i dalej nic, co robię źle?? Oto kod w C# do Compact Framework:
using using System.IO;
public static FileAttributes GetAttributes(string path)
{
if(path.Length > 260)
{
throw new PathTooLongException();
}
if(path.Trim().Length == 0)
{
throw new ArgumentException();
}
uint attr = GetFileAttributes(path);
if(attr == 0xFFFFFFFF)
{
int e = Marshal.GetLastWin32Error();
if((e == 2) || (e == 3))
{
throw new FileNotFoundException();
}
else
{
throw new Exception("Unmanaged Error: " + e);
}
}
return (FileAttributes)attr;
}
public static void SetAttributes(string path, FileAttributes fileAttributes)
{
if(path.Length > 260)
{
throw new PathTooLongException();
}
if(path.Trim().Length == 0)
{
throw new ArgumentException();
}
if(! SetFileAttributes(path, (uint)fileAttributes))
{
int e = Marshal.GetLastWin32Error();
if((e == 2) || (e == 3))
{
throw new FileNotFoundException();
}
else
{
throw new Exception("Unmanaged Error: " + e);
}
}
}
private void renameFolderName(string srcPatch, string dstPatch)
{
DirectoryInfo fl = new DirectoryInfo(srcPatch);
//uint attr = GetFileAttributes(srcPatch);
//attr -= (uint)FileAttributes.ReadOnly;
if(fl.Exists==true)
{
try
{
// remove readonly attribute
if ((fl.Attributes & System.IO.FileAttributes.ReadOnly) != 0)
fl.Attributes -= System.IO.FileAttributes.ReadOnly;
if ((fl.Attributes & System.IO.FileAttributes.Archive) != 0)
fl.Attributes -= System.IO.FileAttributes.Archive;
if ((fl.Attributes & System.IO.FileAttributes.System) != 0)
fl.Attributes -= System.IO.FileAttributes.System;
if ((fl.Attributes & System.IO.FileAttributes.Hidden) != 0)
fl.Attributes -= System.IO.FileAttributes.Hidden;
// fl.Attributes = System.IO.FileAttributes.Normal;
SetAttributes(srcPatch, fl.Attributes);
SetAttributes(srcPatch, System.IO.FileAttributes.Normal);
fl.MoveTo(dstPatch);
}
catch(Exception e)
{
MessageBox.Show("Nie można zmienić nazwy pliku: "+srcPatch,e.ToString());
}
}
else
{
// MessageBox.Show("Plik o ścieżce "+srcPatch+" nie istnieje!");
}
}