[jcifs] leading space char in smb file name

Michael B Allen ioplex at gmail.com
Fri Apr 13 20:07:05 MDT 2012

On Wed, Apr 11, 2012 at 5:21 PM, Anonymous
<nobody at remailer.paranoici.org> wrote:
> Hi,
> I had a problem with the SmbFile.
> I had a file with name "smb://server/share/folder/ foo.bar" on a smb server  ( foo.bar with leading blank). This file was created with jcifs, but calling
> new SmbFile("smb://server/share/folder/").listFiles[0].getName() only returns "foo.bar" with no leading blank.
> Before I had this problem, I didn't believe that it is possible to have files with leading blanks...
> I've analyzed the problem, and figured out, that everything is transfered correct from the server to jcifs.
> In the internal variable unc the path is stored with blank, but in canon, what is used for get name it's not.
> I hope that helps improving jcifs

Hi Michael,

This is a known problem. It is the java.net.URL class that is doing
it. When the listFiles routine calls the SmbFile constructor the name
is passed to the URL class which is trimming the space. There are
other characters that are known to cause problems like this such as #
at the end of names. There's not much we can do about it other than to
dump the java.net.URL class at some point but that would require a
complete re-write.

Note that if you use an SmbFilenameFilter you can get to the
un-trimmed filename. But I don't know if that will help you because I
don't know if you will be able to create an SmbFile instance with it.


Michael B Allen
Java Active Directory Integration

More information about the jCIFS mailing list