回答編集履歴
2
見直しキャンペーン中
test
CHANGED
@@ -1,223 +1,115 @@
|
|
1
1
|
`Windows Runtime API`使う場合は、`Microsoft.Windows.SDK.Contracts`をNuGetしてください。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
何でもかんでも使えるというわけではないと思いますが、
|
6
|
-
|
7
4
|
[ファイルとフォルダーの列挙と照会 - UWP applications | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/uwp/files/quickstart-listing-files-and-folders)
|
8
|
-
|
9
5
|
のサンプルは実行できました。
|
10
|
-
|
11
|
-
|
12
6
|
|
13
7
|
---
|
14
8
|
|
15
|
-
|
16
|
-
|
17
9
|
あまり詳しくないので何が問題なのかわからないです^^;
|
18
|
-
|
19
10
|
同じようにコンソールアプリを`.NET Flamework4.7.2`で作ったのですが。
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
Program.cs
|
12
|
+
```cs:Program.cs
|
24
|
-
|
25
|
-
```C#
|
26
|
-
|
27
13
|
using System;
|
28
|
-
|
29
14
|
using System.Collections.Generic;
|
30
|
-
|
31
15
|
using System.Text;
|
32
|
-
|
33
16
|
using System.Threading.Tasks;
|
34
|
-
|
35
17
|
using Windows.Storage;
|
36
18
|
|
37
|
-
|
38
|
-
|
39
19
|
namespace Questions277082
|
40
|
-
|
41
20
|
{
|
42
|
-
|
43
21
|
class Program
|
44
|
-
|
45
22
|
{
|
46
|
-
|
47
23
|
static async Task Main()
|
48
|
-
|
49
24
|
{
|
50
|
-
|
51
25
|
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
|
52
|
-
|
53
26
|
StringBuilder outputText = new StringBuilder();
|
54
|
-
|
55
|
-
|
56
27
|
|
57
28
|
IReadOnlyList<StorageFile> fileList = await picturesFolder.GetFilesAsync();
|
58
29
|
|
59
|
-
|
60
|
-
|
61
30
|
outputText.AppendLine("Files:");
|
62
|
-
|
63
31
|
foreach(StorageFile file in fileList)
|
64
|
-
|
65
32
|
{
|
66
|
-
|
67
33
|
outputText.Append(file.Name + "\n");
|
68
|
-
|
69
34
|
}
|
70
|
-
|
71
|
-
|
72
35
|
|
73
36
|
IReadOnlyList<StorageFolder> folderList = await picturesFolder.GetFoldersAsync();
|
74
37
|
|
75
|
-
|
76
|
-
|
77
38
|
outputText.AppendLine("Folders:");
|
78
|
-
|
79
39
|
foreach(StorageFolder folder in folderList)
|
80
|
-
|
81
40
|
{
|
82
|
-
|
83
41
|
outputText.Append(folder.DisplayName + "\n");
|
84
|
-
|
85
42
|
}
|
86
43
|
|
87
|
-
|
88
|
-
|
89
44
|
Console.WriteLine(outputText);
|
90
|
-
|
91
45
|
Console.ReadKey();
|
92
|
-
|
93
46
|
}
|
94
|
-
|
95
47
|
}
|
96
|
-
|
97
48
|
}
|
98
|
-
|
99
49
|
```
|
100
50
|
|
51
|
+
```xml:Questions277082.csproj
|
52
|
+
<?xml version="1.0" encoding="utf-8"?>
|
53
|
+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
54
|
+
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
55
|
+
<PropertyGroup>
|
56
|
+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
57
|
+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
58
|
+
<ProjectGuid>{C9C0ADED-9797-41F4-8BFC-A0A770D3AC5A}</ProjectGuid>
|
59
|
+
<OutputType>Exe</OutputType>
|
60
|
+
<RootNamespace>Questions277082</RootNamespace>
|
61
|
+
<AssemblyName>Questions277082</AssemblyName>
|
62
|
+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
63
|
+
<FileAlignment>512</FileAlignment>
|
64
|
+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
65
|
+
<Deterministic>true</Deterministic>
|
66
|
+
</PropertyGroup>
|
67
|
+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
68
|
+
<PlatformTarget>AnyCPU</PlatformTarget>
|
69
|
+
<DebugSymbols>true</DebugSymbols>
|
70
|
+
<DebugType>full</DebugType>
|
71
|
+
<Optimize>false</Optimize>
|
72
|
+
<OutputPath>bin\Debug\</OutputPath>
|
73
|
+
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
74
|
+
<ErrorReport>prompt</ErrorReport>
|
75
|
+
<WarningLevel>4</WarningLevel>
|
76
|
+
</PropertyGroup>
|
77
|
+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
78
|
+
<PlatformTarget>AnyCPU</PlatformTarget>
|
79
|
+
<DebugType>pdbonly</DebugType>
|
80
|
+
<Optimize>true</Optimize>
|
81
|
+
<OutputPath>bin\Release\</OutputPath>
|
82
|
+
<DefineConstants>TRACE</DefineConstants>
|
83
|
+
<ErrorReport>prompt</ErrorReport>
|
84
|
+
<WarningLevel>4</WarningLevel>
|
85
|
+
</PropertyGroup>
|
86
|
+
<ItemGroup>
|
87
|
+
<Reference Include="System" />
|
88
|
+
<Reference Include="System.Core" />
|
89
|
+
<Reference Include="System.Xml.Linq" />
|
90
|
+
<Reference Include="System.Data.DataSetExtensions" />
|
91
|
+
<Reference Include="Microsoft.CSharp" />
|
92
|
+
<Reference Include="System.Data" />
|
93
|
+
<Reference Include="System.Net.Http" />
|
94
|
+
<Reference Include="System.Xml" />
|
95
|
+
</ItemGroup>
|
96
|
+
<ItemGroup>
|
97
|
+
<Compile Include="Program.cs" />
|
98
|
+
<Compile Include="Properties\AssemblyInfo.cs" />
|
99
|
+
</ItemGroup>
|
100
|
+
<ItemGroup>
|
101
|
+
<None Include="App.config" />
|
102
|
+
</ItemGroup>
|
103
|
+
<ItemGroup>
|
104
|
+
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
|
105
|
+
<Version>10.0.19041.1</Version>
|
106
|
+
</PackageReference>
|
107
|
+
</ItemGroup>
|
108
|
+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
109
|
+
</Project>
|
110
|
+
```
|
101
111
|
|
112
|
+
---
|
102
113
|
|
103
|
-
|
114
|
+
.NET 6 以降はTFMの追加のみで、使用できるようになっています。
|
104
|
-
|
105
|
-
```xml
|
106
|
-
|
107
|
-
<?xml version="1.0" encoding="utf-8"?>
|
108
|
-
|
109
|
-
|
115
|
+
[デスクトップ アプリで Windows ランタイム API を呼び出す - Windows apps | Microsoft Learn](https://learn.microsoft.com/ja-jp/windows/apps/desktop/modernize/desktop-to-uwp-enhance)
|
110
|
-
|
111
|
-
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
112
|
-
|
113
|
-
<PropertyGroup>
|
114
|
-
|
115
|
-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
116
|
-
|
117
|
-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
118
|
-
|
119
|
-
<ProjectGuid>{C9C0ADED-9797-41F4-8BFC-A0A770D3AC5A}</ProjectGuid>
|
120
|
-
|
121
|
-
<OutputType>Exe</OutputType>
|
122
|
-
|
123
|
-
<RootNamespace>Questions277082</RootNamespace>
|
124
|
-
|
125
|
-
<AssemblyName>Questions277082</AssemblyName>
|
126
|
-
|
127
|
-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
128
|
-
|
129
|
-
<FileAlignment>512</FileAlignment>
|
130
|
-
|
131
|
-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
132
|
-
|
133
|
-
<Deterministic>true</Deterministic>
|
134
|
-
|
135
|
-
</PropertyGroup>
|
136
|
-
|
137
|
-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
138
|
-
|
139
|
-
<PlatformTarget>AnyCPU</PlatformTarget>
|
140
|
-
|
141
|
-
<DebugSymbols>true</DebugSymbols>
|
142
|
-
|
143
|
-
<DebugType>full</DebugType>
|
144
|
-
|
145
|
-
<Optimize>false</Optimize>
|
146
|
-
|
147
|
-
<OutputPath>bin\Debug\</OutputPath>
|
148
|
-
|
149
|
-
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
150
|
-
|
151
|
-
<ErrorReport>prompt</ErrorReport>
|
152
|
-
|
153
|
-
<WarningLevel>4</WarningLevel>
|
154
|
-
|
155
|
-
</PropertyGroup>
|
156
|
-
|
157
|
-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
158
|
-
|
159
|
-
<PlatformTarget>AnyCPU</PlatformTarget>
|
160
|
-
|
161
|
-
<DebugType>pdbonly</DebugType>
|
162
|
-
|
163
|
-
<Optimize>true</Optimize>
|
164
|
-
|
165
|
-
<OutputPath>bin\Release\</OutputPath>
|
166
|
-
|
167
|
-
<DefineConstants>TRACE</DefineConstants>
|
168
|
-
|
169
|
-
<ErrorReport>prompt</ErrorReport>
|
170
|
-
|
171
|
-
<WarningLevel>4</WarningLevel>
|
172
|
-
|
173
|
-
</PropertyGroup>
|
174
|
-
|
175
|
-
<ItemGroup>
|
176
|
-
|
177
|
-
<Reference Include="System" />
|
178
|
-
|
179
|
-
<Reference Include="System.Core" />
|
180
|
-
|
181
|
-
<Reference Include="System.Xml.Linq" />
|
182
|
-
|
183
|
-
<Reference Include="System.Data.DataSetExtensions" />
|
184
|
-
|
185
|
-
<Reference Include="Microsoft.CSharp" />
|
186
|
-
|
187
|
-
<Reference Include="System.Data" />
|
188
|
-
|
189
|
-
<Reference Include="System.Net.Http" />
|
190
|
-
|
191
|
-
<Reference Include="System.Xml" />
|
192
|
-
|
193
|
-
</ItemGroup>
|
194
|
-
|
195
|
-
<ItemGroup>
|
196
|
-
|
197
|
-
<Compile Include="Program.cs" />
|
198
|
-
|
199
|
-
<Compile Include="Properties\AssemblyInfo.cs" />
|
200
|
-
|
201
|
-
</ItemGroup>
|
202
|
-
|
203
|
-
<ItemGroup>
|
204
|
-
|
205
|
-
<None Include="App.config" />
|
206
|
-
|
207
|
-
</ItemGroup>
|
208
|
-
|
209
|
-
<ItemGroup>
|
210
|
-
|
211
|
-
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
|
212
|
-
|
213
|
-
<Version>10.0.19041.1</Version>
|
214
|
-
|
215
|
-
</PackageReference>
|
216
|
-
|
217
|
-
</ItemGroup>
|
218
|
-
|
219
|
-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
220
|
-
|
221
|
-
</Project>
|
222
|
-
|
223
|
-
```
|
1
コード追記
test
CHANGED
@@ -7,3 +7,217 @@
|
|
7
7
|
[ファイルとフォルダーの列挙と照会 - UWP applications | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/uwp/files/quickstart-listing-files-and-folders)
|
8
8
|
|
9
9
|
のサンプルは実行できました。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
あまり詳しくないので何が問題なのかわからないです^^;
|
18
|
+
|
19
|
+
同じようにコンソールアプリを`.NET Flamework4.7.2`で作ったのですが。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
Program.cs
|
24
|
+
|
25
|
+
```C#
|
26
|
+
|
27
|
+
using System;
|
28
|
+
|
29
|
+
using System.Collections.Generic;
|
30
|
+
|
31
|
+
using System.Text;
|
32
|
+
|
33
|
+
using System.Threading.Tasks;
|
34
|
+
|
35
|
+
using Windows.Storage;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
namespace Questions277082
|
40
|
+
|
41
|
+
{
|
42
|
+
|
43
|
+
class Program
|
44
|
+
|
45
|
+
{
|
46
|
+
|
47
|
+
static async Task Main()
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
|
52
|
+
|
53
|
+
StringBuilder outputText = new StringBuilder();
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
IReadOnlyList<StorageFile> fileList = await picturesFolder.GetFilesAsync();
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
outputText.AppendLine("Files:");
|
62
|
+
|
63
|
+
foreach(StorageFile file in fileList)
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
outputText.Append(file.Name + "\n");
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
IReadOnlyList<StorageFolder> folderList = await picturesFolder.GetFoldersAsync();
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
outputText.AppendLine("Folders:");
|
78
|
+
|
79
|
+
foreach(StorageFolder folder in folderList)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
outputText.Append(folder.DisplayName + "\n");
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
Console.WriteLine(outputText);
|
90
|
+
|
91
|
+
Console.ReadKey();
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
Questions277082.csproj
|
104
|
+
|
105
|
+
```xml
|
106
|
+
|
107
|
+
<?xml version="1.0" encoding="utf-8"?>
|
108
|
+
|
109
|
+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
110
|
+
|
111
|
+
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
112
|
+
|
113
|
+
<PropertyGroup>
|
114
|
+
|
115
|
+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
116
|
+
|
117
|
+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
118
|
+
|
119
|
+
<ProjectGuid>{C9C0ADED-9797-41F4-8BFC-A0A770D3AC5A}</ProjectGuid>
|
120
|
+
|
121
|
+
<OutputType>Exe</OutputType>
|
122
|
+
|
123
|
+
<RootNamespace>Questions277082</RootNamespace>
|
124
|
+
|
125
|
+
<AssemblyName>Questions277082</AssemblyName>
|
126
|
+
|
127
|
+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
128
|
+
|
129
|
+
<FileAlignment>512</FileAlignment>
|
130
|
+
|
131
|
+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
132
|
+
|
133
|
+
<Deterministic>true</Deterministic>
|
134
|
+
|
135
|
+
</PropertyGroup>
|
136
|
+
|
137
|
+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
138
|
+
|
139
|
+
<PlatformTarget>AnyCPU</PlatformTarget>
|
140
|
+
|
141
|
+
<DebugSymbols>true</DebugSymbols>
|
142
|
+
|
143
|
+
<DebugType>full</DebugType>
|
144
|
+
|
145
|
+
<Optimize>false</Optimize>
|
146
|
+
|
147
|
+
<OutputPath>bin\Debug\</OutputPath>
|
148
|
+
|
149
|
+
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
150
|
+
|
151
|
+
<ErrorReport>prompt</ErrorReport>
|
152
|
+
|
153
|
+
<WarningLevel>4</WarningLevel>
|
154
|
+
|
155
|
+
</PropertyGroup>
|
156
|
+
|
157
|
+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
158
|
+
|
159
|
+
<PlatformTarget>AnyCPU</PlatformTarget>
|
160
|
+
|
161
|
+
<DebugType>pdbonly</DebugType>
|
162
|
+
|
163
|
+
<Optimize>true</Optimize>
|
164
|
+
|
165
|
+
<OutputPath>bin\Release\</OutputPath>
|
166
|
+
|
167
|
+
<DefineConstants>TRACE</DefineConstants>
|
168
|
+
|
169
|
+
<ErrorReport>prompt</ErrorReport>
|
170
|
+
|
171
|
+
<WarningLevel>4</WarningLevel>
|
172
|
+
|
173
|
+
</PropertyGroup>
|
174
|
+
|
175
|
+
<ItemGroup>
|
176
|
+
|
177
|
+
<Reference Include="System" />
|
178
|
+
|
179
|
+
<Reference Include="System.Core" />
|
180
|
+
|
181
|
+
<Reference Include="System.Xml.Linq" />
|
182
|
+
|
183
|
+
<Reference Include="System.Data.DataSetExtensions" />
|
184
|
+
|
185
|
+
<Reference Include="Microsoft.CSharp" />
|
186
|
+
|
187
|
+
<Reference Include="System.Data" />
|
188
|
+
|
189
|
+
<Reference Include="System.Net.Http" />
|
190
|
+
|
191
|
+
<Reference Include="System.Xml" />
|
192
|
+
|
193
|
+
</ItemGroup>
|
194
|
+
|
195
|
+
<ItemGroup>
|
196
|
+
|
197
|
+
<Compile Include="Program.cs" />
|
198
|
+
|
199
|
+
<Compile Include="Properties\AssemblyInfo.cs" />
|
200
|
+
|
201
|
+
</ItemGroup>
|
202
|
+
|
203
|
+
<ItemGroup>
|
204
|
+
|
205
|
+
<None Include="App.config" />
|
206
|
+
|
207
|
+
</ItemGroup>
|
208
|
+
|
209
|
+
<ItemGroup>
|
210
|
+
|
211
|
+
<PackageReference Include="Microsoft.Windows.SDK.Contracts">
|
212
|
+
|
213
|
+
<Version>10.0.19041.1</Version>
|
214
|
+
|
215
|
+
</PackageReference>
|
216
|
+
|
217
|
+
</ItemGroup>
|
218
|
+
|
219
|
+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
220
|
+
|
221
|
+
</Project>
|
222
|
+
|
223
|
+
```
|