Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>class zfilename</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
class zFileName

Usage

    #include <fname.hpp>
    zFileName ...;

Description

    // There are three constructors, a default constructor (no arguments),
    // one which takes a filename string as an argument,  and optionally
    // allows characters to be excluded from the filename.  The default
    // value for this second parameter is the list of characters which
    // are officially prohibited from a DOS file name or extension.
    // The final constructor is a copy constructor.

        zFileName();
        zFileName(const char *, const char * = " *+=[]:;\",.?/");
        zFileName(const zFileName&);
        zFileName& operator=(const zFileName&);

    // The next set of functions give access to the constituent parts of
    // the filename.

        char drive() const { return _drive; }
        const char *name() const { return _name; }
        const char *ext() const { return _ext; }
        const char *path() const { return _path; }

    // The next three functions modify the zFileName object.  The action
    // of the build function is determined by its defaulted final argument.
    // If this is non-zero, then the effect is to modify only the components
    // of the filename for which there are non-zero arguments.  If the final
    // argument is zero, then the arguments override the existing values
    // unconditionally.

        int build(char drv, const char *pth ,
                const char *nm, const char *ex, int = 1);

    // operator() returns the complete filename.

        const char *operator()();

    // The parse function takes apart the supplied string, and determines
    // whether it is a legal filename.

        int parse(const char *);
        int error() { int e = err; err = 0; return e; }
        ~zFileName() { delete _path; delete fn; }

Example 

    #include <stdlib.h>
    #include <iostream.hpp>
    #include <io.h>
    #include <fname.hpp>

    //. It will be convenient for the test program to have some descriptive
    //. strings for the various errors which can arise.
    char *errmess[] = {
        "No memory",
        "Drive letter out of range",
        "Drive specifier incorrect",
        "Path > 64 characters",
        "Directory names 8 chars only",
        "File name too long",
        "Extension too long",
        "Illegal character",
        ""
    };

    main(int argc, char *argv[])
    {

    //. Then declare a null #zFileName using no arguments, and use it to
    //. parse the filename hopefully supplied as part of the command line.
        zFileName f;
        int x;
        long len;

        if (argc > 1) {
            if ((x = f.parse(argv[1])) != 0) {

    //. If parsing finds fault with the filename then describe why, otherwise
    //. determine if the file exists, and if it does, then display its
    //. size.
                int i = x > ENOMEM? x+1-FN_BADDRIVE: 0;
                cout << errmess[i];
            } else {
                len = filesize((char *) f());
                if (len >= 0L)
                    cout << "File length is " << len << endl;
                else
                    cout << "File does not exist";
            }
        } else
            cout <<
    "file name argument required - bad or good!";
        return EXIT_SUCCESS;
    }

See Also






Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson