# Create directories, read files and create file

**URL:** <https://discourse.julialang.org/t/create-directories-read-files-and-create-file/110855>\
**Category:** General Usage\
**Tags:** write\
**Created:** [February 27, 2024, 4:13pm UTC](https://discourse.julialang.org/t/create-directories-read-files-and-create-file/110855 "2024-02-27T16:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [February 27, 2024, 4:13pm UTC](https://discourse.julialang.org/t/create-directories-read-files-and-create-file/110855/1 "2024-02-27T16:13:10Z")

</div>

I have this program in C++ (but even Python) which opens or creates a directory called file\_path, scrolls each text file which goes along the Data\_xyzw.txt format, finds the bigger xyzw and creates a name which is Data\_abcd.txt where abcd = xyzw+1:

```julia
extern "C" void file_digits_finder (char* file_path){
    
    //creating folder
    int status = 0;
    status = mkdir(file_path, S_IRWXU | S_IRWXO);

    //getting names from all files in folder if already existent
    uint higher_number = 0;
    if (status==-1){
        DIR *folder;
        struct dirent *entry;
        int files = 0;

        folder = opendir(file_path);
        assert(folder);
    // All files will be of type: Data_xyzw, so 5 nondigit and 4 digits

        while( (entry = readdir(folder)) ){
            files++;
            uint file_number = 0;
            if ( isdigit(entry->d_name[5])!=0 && isdigit(entry->d_name[6])!=0 && isdigit(entry->d_name[7])!=0 && isdigit(entry->d_name[8])!=0){
                string digits = to_string(entry->d_name[5]-48) + to_string(entry->d_name[6]-48) + to_string(entry->d_name[7]-48) + to_string(entry->d_name[8]-48) ;
                file_number = stoi(digits);
            }
            if (higher_number < file_number){
                higher_number = file_number;
            }
            //file will all be of the same name "Data" + a "file_number". We want to create a new file.
        }
        closedir(folder);
    }

    //decing file_number
    previous_file_digits = higher_number;
}

```

How can I write this in julia?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [February 27, 2024, 5:19pm UTC](https://discourse.julialang.org/t/create-directories-read-files-and-create-file/110855/2 "2024-02-27T17:19:26Z")

</div>

I think with these functions you get all you need:

[https://docs.julialang.org/en/v1/base/file/](https://docs.julialang.org/en/v1/base/file/)
