Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5357

Create directory in CVI

$
0
0

Hi,

I want to create directory in CVI.  did not know that C does not have a native function for it.  I tried this code (with some built-in error checks) but it seems to have some errors:

 

int Folder_Make (char Folder[])
{
    //this function takes in argument with single forward slash(es) (FS),
    //replaces them with double FS, then try to create intended folder
    int     result      =   0;
    int     len_Folder  =   strlen (Folder);
    int     len_New;    
    int     FS_count    =   0;
    int     FS_last     =   0;  //last FS flag
    int     FS_max      =   5;  //max FS
    int     FS_pos [FS_max];
    char   *MyFolder;

    //count FS
    for (int i = 0; i < len_Folder; i++)
    {
        if (Folder [i] == '\\')
        {
            FS_pos [FS_count] = i;  //FS position
            FS_count++;             //FS count
        }
    }

    //add last FS if necessary
    if (Folder [len_Folder - 1] != '\\')    FS_last = 1;
    if ((FS_last) && (FS_count < FS_max))
    {
        FS_pos [FS_count] = len_Folder; //FS position
        FS_count++;
    }

    //check for consecutive FS prior to correction
    for (int i = 0; i < (FS_count - 1); i++)
    {
        if (FS_pos [i] == FS_pos [i + 1])   result = -1;
    }

    if (!result)    //still no error
    {
        len_New     =   len_Folder + FS_count;      if (FS_last)    len_New++;
        MyFolder    =   malloc (len_New + 1);

        for (int i = 0, j = 0; i < len_Folder; i++, j++)
        {
                                        MyFolder [j]        =   Folder [i];
            if (Folder [i] == '\\')
            {                           j++;
                                        MyFolder [j]        =   '\\';
            }

            if (i == len_Folder - 1)
            {                           j++;
                                        MyFolder [j]        =   '\\';
                if (FS_last)
                {                       j++;
                                        MyFolder [j]        =   '\\';
                }
            }
        }
                                        MyFolder [len_New]  =   '\0';   //null-termination
    }

    //create folder
    MakeDir (MyFolder);

    return result;
/*  error value
    -1      consecutive FS found
*/
}

 

please help.


Viewing all articles
Browse latest Browse all 5357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>