我知道如何在应用程序中创建一个文件夹,如下所示:
print("Enter the item number:")
line_count = 0
marked_item = int(input())
with open("items.csv", 'r') as f:
reader = csv.DictReader(f, delimiter=',')
for line in reader:
if line["item_required"] == 'r':
line_count += 1
if marked_item == line_count:
new_list = line
print(new_list)
for key, value in new_list.items():
if value == "r":
new_list['item_required'] = "x"
print(new_list)
with open("items.csv", 'a') as f:
writer = csv.writer(f)
writer.writerow(new_list.values())
但是如何在C:\?
中创建文件夹 // Get the app's local folder.
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
string desiredName = "Subfolder";
StorageFolder newFolder = await localFolder.CreateFolderAsync(desiredName,CreationCollisionOption.FailIfExists);
以上不起作用。
感谢您的帮助。
由于
答案 0 :(得分:2)
但是如何在C:\?
中创建文件夹
要在C:\
中创建文件夹,您需要使用FolderPicker来获取该文件夹。然后使用StorageFolder.CreateFolderAsync创建一个文件夹:
var picker=new Windows.Storage.Pickers.FolderPicker();
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
picker.FileTypeFilter.Add(".exe");//add any extension to avoid exception
var folder=await picker.PickSingleFolderAsync();
if (folder != null)
{
var myNewFolder=await folder.CreateFolderAsync("myNewFolder");
}
您可以将文件夹保存在FutureAccessList中,以后可以创建没有选择器的子文件夹:
Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
获取没有选择器的文件夹:
var folder = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFolderAsync("PickedFolderToken");
if (folder != null)
{
var newFolder=folder.CreateFolderAsync("myQuiteFolder");
}
以下是演示:SaveFolderSample。