[jcifs] create directory hierarchy - mkdirs()
Michael B Allen
mballen at erols.com
Thu Mar 14 07:24:26 EST 2002
On Wed, 13 Mar 2002 20:38:22 +0100
Klemens.Dickbauer.extern at HVBSystems.com wrote:
> 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.
No, there's no SMB specific function for this. You would have to do
something like you have done.
Mike
> 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();
> }
>
--
May The Source be with you.
More information about the jcifs
mailing list