hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
695 stars 178 forks source link

SBMJ implements fileNameFilter #599

Open mausan-IT opened 3 years ago

mausan-IT commented 3 years ago

Hello

I working with a remote directory. In my first approche, used JCIFS and filter files by name with implementation of SmbFilenameFilter.

Now I need to do the same operation with SBMJ. There is an equivalent class in SBMJ? How I can do that?

My original Code:

static class TxsFilenameFilter implements SmbFilenameFilter {

    private String numero_txs;

    public TxsFilenameFilter(String extension) {
        this.numero_txs = extension.toLowerCase();
    }

    public boolean accept( SmbFile dir, String name ) throws SmbException {
            return name.startsWith(numero_txs);
        }
}   
hierynomus commented 3 years ago

You can either specify a searchPattern on the Directory.list(Class informationClass, String searchPattern), which ensures that the filtering is done server side. Or you just call Directory.list() and need to do the filtering client side using a for loop over the results.

From the JavaDoc:

     * Two wild card characters are supported in the search pattern. The "?" (question mark) character matches a single
     * character. If a search pattern contains one or more "?" characters, then exactly that number of characters is
     * matched by the wildcards. For example, the criterion "??x" matches "abx" but not "abcx" or "ax", because the two
     * file names do not have enough characters preceding the literal. When a file name criterion has "?" characters
     * trailing a literal, then the match is made with specified number of characters or less. For example, the
     * criterion "x??" matches "xab", "xa", and "x", but not "xabc". If only "?" characters are present in the file name
     * selection criterion, then the match is made as if the criterion contained "?" characters trailing a literal.
     * The "*" (asterisk) character matches an entire file name. A null or empty specification criterion also selects
     * all file names. For example, "*.abc" or ".abc" match any file with an extension of "abc". "*.*", "*", or empty
     * string("") match all files in a directory.
hierynomus commented 3 years ago

Does this answer your question @mausan-IT

qiuhuanhen commented 1 year ago

You can either specify a searchPattern on the Directory.list(Class informationClass, String searchPattern), which ensures that the filtering is done server side. Or you just call Directory.list() and need to do the filtering client side using a for loop over the results.

From the JavaDoc:

     * Two wild card characters are supported in the search pattern. The "?" (question mark) character matches a single
     * character. If a search pattern contains one or more "?" characters, then exactly that number of characters is
     * matched by the wildcards. For example, the criterion "??x" matches "abx" but not "abcx" or "ax", because the two
     * file names do not have enough characters preceding the literal. When a file name criterion has "?" characters
     * trailing a literal, then the match is made with specified number of characters or less. For example, the
     * criterion "x??" matches "xab", "xa", and "x", but not "xabc". If only "?" characters are present in the file name
     * selection criterion, then the match is made as if the criterion contained "?" characters trailing a literal.
     * The "*" (asterisk) character matches an entire file name. A null or empty specification criterion also selects
     * all file names. For example, "*.abc" or ".abc" match any file with an extension of "abc". "*.*", "*", or empty
     * string("") match all files in a directory.

hello , if I want to get the files with createTime < LocalDate.now().atStartOfDay , could the searchPattern work? From the doc , I couldn't see it

hierynomus commented 1 year ago

Hi,

No, the searchPattern is based on name only. There is no way to do server-side filtering on creation or modification times. This will need to happen client-side.