How to create folders within the program's own subfolder? [closed]

-3

How to create folders within the program's own subfolder, even if the user leaves the program anywhere on the computer ?

All the media I found would be with paths already determined and the other method was in assembly, however, I'm not familiar with the assembly.

The idea is that the program will check if the folder exists and if it exists, it checks if there are files inside, after that, the program will copy all the contents and play to another predefined folder.

    
asked by anonymous 22.08.2017 / 12:00

2 answers

0

The best way to do this is by grabbing the executable directory and then pasting the folders, as follows:

string dirPrograma = Path.GetDirectoryName(Application.ExecutablePath);

if(!Directory.Exist(Path.Combine(dirPrograma, "Downloads")))
    Directory.CreateDirectory(Path.Combine(dirPrograma, "Downloads"));

This ensures that regardless of where the program is running and its home directory (calling from a command prompt or shortcut with a different home directory), it will be created in the program folder.

    
22.08.2017 / 13:28
1

Suppose your program is on the following path

  

C: \ Users \ JhonSnow \ Documents \ GOT \ got.exe

For the program to check if the folder exists inside the GOT folder

if(!Directory.Exist("Downloads"))
    Directory.CreateDirectory("Downloads");

In this way the system will understand that it is in the same folder as the executable, after that the GOT Directory would look like this

  • C: \
    • Users
      • JhonSnow
        • Documents
          • GOT
            • Downloads
            • got.exe
            • got.exe.config

And even if you change the location of the program the rule continues, it will always create a folder where the executable is.

    
22.08.2017 / 13:03