(ModifiedTime を更新) WinRT でファイルを「タッチ」するエレガントでパフォーマンスの高い方法は?
30 日以上経過したファイルを削除する必要があるコードがいくつかあります。これはうまく機能しますが、場合によっては、ファイルの時間を更新して 30 日のウィンドウをリセットし、削除を防ぐ必要があります。basicProperties リストでは、ModifiedTime は読み取り専用なので、更新する別の方法を見つける必要があります...
方法 1: 名前を 2 回変更する
// Ugly, and may have side-effects depending on what's using the file
// Sometimes gives access denied...
public static async Task TouchFileAsync(this StorageFile file)
{
var name = file.Name;
await file.RenameAsync("~" + name).AsTask().ContinueWith(
async (task) => { await file.RenameAsync(name); }
);
}
方法 2: ファイル プロパティを変更する
// Sometimes works, but currently throwing an ArgumentException for
// me, and I have no idea why. Also tried many other properties:
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb760658(v=vs.85).aspx
public static async Task TouchFileAsync(this StorageFile file)
{
var prop = new KeyValuePair<string, object>("System.Comment", DateTime.Now.Ticks.ToString());
await file.Properties.SavePropertiesAsync(new[] { prop });
}
方法 3: P/Invoke 経由で Win32 API を使用しますか?
- これが ARM デバイスで動作するかどうかわかりませんか?
- 合格認定?
- 高性能ですか?
- これを行う最善の方法はありますか?コードサンプル?
他のアイデアはありますか?私は少し立ち往生しています:-)
どうもありがとう、ジョン