Decompose File Specification c++

A process for file specification decomposition is often required.  To achieve decomposition goals we employ a structure and a method.

The structure is as follows.

[codesyntax lang=”cpp”]

    struct filespecification_area
    {
        string Path;
        string File;
    };

[/codesyntax]

Establish a pointer to the structure by declaring the following.

[codesyntax lang=”cpp”]

    filespecification_area fs;

[/codesyntax]

The associated method is listed below.

[codesyntax lang=”cpp”]

string makeDebFrame::retPathFn(string fileSpec)
{
    int flo = fileSpec.find_last_of("/");
    fs.Path = fileSpec.substr(0, flo + 1);
    fs.File = fileSpec.substr((flo + 1), fileSpec.length());

}

[/codesyntax]

To invoke the method a call to the following code in required.

[codesyntax lang=”cpp”]

    retPathFn(GetFileName(""));

[/codesyntax]

The GetFileName method is listed below.

[codesyntax lang=”cpp”]

string makeDebFrame::GetFileName(string fs)
{
    wxFileDialog openFileDialog(this, _("Open Any file"), defPath, fno, fs, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
    if (openFileDialog.ShowModal() == wxID_CANCEL)
    {
        fileSpec = " ";
    }
    else
    {
        fileSpec = openFileDialog.GetPath();
    }

    return fileSpec;

}

[/codesyntax]

To support the above method the following items must be declared.

[codesyntax lang=”cpp”]

        string defPath = "";
    string fno = "";

[/codesyntax]

This utility will allow the programmer to decompose file specifications properly.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *