Skip to content

Commit 4851a31

Browse files
committed
💾 Feat(SyncCodes): Make sure folder of file exists
1 parent 512ee4c commit 4851a31

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎Utils/SyncCodes/Program.cs

+12
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ await catalogResponse.Content.ReadAsStringAsync(),
199199
}
200200

201201
var fileContent = await fileContentResponse.Content.ReadAsStringAsync();
202+
MakeSureFolderExists(filePath);
202203
File.WriteAllText(filePath, fileContent);
203204
}
204205
}
@@ -253,6 +254,17 @@ string HomePageHtml(
253254
</html>
254255
""";
255256

257+
void MakeSureFolderExists(string path)
258+
{
259+
var directory = Path.GetDirectoryName(path);
260+
if (directory is null) return;
261+
262+
var directoryInfo = new DirectoryInfo(Path.GetFullPath(directory));
263+
264+
if (!directoryInfo.Exists)
265+
directoryInfo.Create();
266+
}
267+
256268
partial class Program
257269
{
258270
[GeneratedRegex(@"([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|(\[[0-9A-Fa-f:.]+\])|([a-zA-Z0-9.-]+)(:\d+)?")]

0 commit comments

Comments
 (0)