How to create folder structure when app loaded.

Dani_S 3,686 Reputation points
2024-07-11T10:36:07.6766667+00:00

Hi,

I'm in net 8 macos.

I want to create on this path :

var lib = FileSystem.AppDataDirectory.

folder name App and inside it folder Logs.

if these folders exists don't create them.

Please add full code ?

Thanks,

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,369 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 63,666 Reputation points
    2024-07-11T15:44:41.9466667+00:00

    create if not exists:

    var libFolder = FileSystem.AppDataDirectory;
    var appFolder = Path.Combine(libFolder,"app");
    var logFolder = Path.Combine(appFolder,"log");
    if (!Directory.Exists(appFolder)) Directory.Create(appFolder);
    if (!Directory.Exists(logFolder)) Directory.Create(logFolder);
    

    note: on macOS .net 8 is a catalyst app, and the data folder is the sandbox folder (~/Library/Containers/<appname>/Data). The install will also create links to common folders that the manifest specifies (Downloads, Movie, Pictures, etc).

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.