[jcifs] create directory hierarchy - mkdirs()

Klemens.Dickbauer.extern at HVBSystems.com Klemens.Dickbauer.extern at HVBSystems.com
Thu Mar 14 06:38:22 EST 2002


Hi!

afaik the api of SmbFile should be relatively close to the one of
java.io.File.
there a method 'mkdirs()' exists to create a full directory hierarchy at
once. since
i'm doing an abstraction class for both File and SmbFile a mkdirs()-method
in SmbFile
as well seems appropriate and handy for me.
i tried to implement one, but using a recursive (very easy ;) descent to a
file that exists
might be quite ineffective (and not stable), so there might be a better
solution of delegating
to some lower-level cifs call.
sorry, i'm quite new and unknowing of this SMB stuff (-:

greetz,
~klemens

--
kdi at msk-informatik . at


p.s.: my try:
--
    /**
     * Creates a directory hierarchy by creating each required directory
     * given by the path of <code>SmbFile</code>. It uses the
     * <code>mkdir()</code>-method of this class.
     *
     * @throws SmbException
     */
    public void mkdirs() throws SmbException {
        if( canonicalPath == null ) {
            throw new SmbException( SmbException.ERRDOS,
                                    SmbException.ERRnoaccess );
        }
        Log.println( Log.WARNINGS, "smb create directory hierarchy warning",
                            " directoryName=" + uncPath );

        // check if parent directory exists and call recursively if not
        SmbFile parentFile = null;
        try {
            parentFile = new SmbFile(this.getParent());
        }
        catch (MalformedURLException e) {
            Log.println(Log.EXCEPTIONS, "smb create dircetory hierarchy
exception",
                    " directoryName=" + parentFile.uncPath);
            throw new SmbException(SmbException.ERRRAP, "Could not create "
+ parentFile.uncPath);
        }
        catch (java.net.UnknownHostException e) {
            Log.println(Log.EXCEPTIONS, "smb create dircetory hierarchy
exception"
                    + ": UnknownHostException: " + e.getLocalizedMessage(),
                    " directoryName=" + parentFile.uncPath);
            throw new SmbException(SmbException.ERRRAP, "Could not create "
+ parentFile.uncPath
                        + ": UnknownHostException: " +
e.getLocalizedMessage());
        }
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        this.mkdir();
    }




More information about the jcifs mailing list