Java Code Examples for jcifs.smb.SmbFile#isDirectory()
The following examples show how to use
jcifs.smb.SmbFile#isDirectory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCIFS_NGController.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public List<SmbFileInfo> getSelfList() { if (isRootDir()) return rootFileList; List<SmbFileInfo> fileInfoList = new ArrayList<>(); try { SmbFile smbFile = new SmbFile(mAuthUrl + mPath, cifsContext); if (smbFile.isDirectory() && smbFile.canRead()) { fileInfoList.addAll(getFileInfoList(smbFile.listFiles())); } } catch (MalformedURLException | SmbException e) { e.printStackTrace(); } return fileInfoList; }
Example 2
Source File: SMBOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
private List<Info> list(SmbFile parent, ListParameters params) throws IOException { if (Thread.currentThread().isInterrupted()) { throw new IOException(FileOperationMessages.getString("IOperationHandler.interrupted")); //$NON-NLS-1$ } if (!parent.exists()) { throw new FileNotFoundException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.file_not_found"), parent.toString())); //$NON-NLS-1$ } if (!parent.isDirectory()) { return Arrays.asList(info(parent)); } SmbFile[] children = ensureTrailingSlash(parent).listFiles(); if (children != null) { List<Info> result = new ArrayList<Info>(); for (SmbFile child: children) { result.add(info(child)); if (params.isRecursive() && child.isDirectory()) { result.addAll(list(child, params)); } } return result; } return new ArrayList<Info>(0); }
Example 3
Source File: SMBOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
private boolean delete(SmbFile file, DeleteParameters params) throws IOException { if (Thread.currentThread().isInterrupted()) { throw new IOException(FileOperationMessages.getString("IOperationHandler.interrupted")); //$NON-NLS-1$ } if (!file.exists()) { throw new FileNotFoundException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.file_not_found"), file.toString())); //$NON-NLS-1$ } if (file.isDirectory()) { if (!params.isRecursive()) { throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.cannot_remove_directory"), file)); //$NON-NLS-1$ } file = ensureTrailingSlash(file); } file.delete(); return true; }
Example 4
Source File: NetworkExplorer.java From jcifs-ng with GNU Lesser General Public License v2.1 | 6 votes |
protected int compareTypes ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { String f2name, t1, t2; int i; if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } f2name = f2.getName(); if ( f1.isDirectory() ) { return f1name.compareToIgnoreCase(f2name); } i = f1name.lastIndexOf('.'); t1 = i == -1 ? "" : f1name.substring(i + 1); i = f2name.lastIndexOf('.'); t2 = i == -1 ? "" : f2name.substring(i + 1); i = t1.compareToIgnoreCase(t2); if ( i == 0 ) { return f1name.compareToIgnoreCase(f2name); } return i; }
Example 5
Source File: NetworkExplorer.java From jcifs with GNU Lesser General Public License v2.1 | 6 votes |
protected int compareTypes ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { String f2name, t1, t2; int i; if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } f2name = f2.getName(); if ( f1.isDirectory() ) { return f1name.compareToIgnoreCase(f2name); } i = f1name.lastIndexOf('.'); t1 = i == -1 ? "" : f1name.substring(i + 1); i = f2name.lastIndexOf('.'); t2 = i == -1 ? "" : f2name.substring(i + 1); i = t1.compareToIgnoreCase(t2); if ( i == 0 ) { return f1name.compareToIgnoreCase(f2name); } return i; }
Example 6
Source File: JCIFS_NGController.java From DanDanPlayForAndroid with MIT License | 6 votes |
private List<SmbFileInfo> getFileInfoList(SmbFile[] smbFiles) { List<SmbFileInfo> fileInfoList = new ArrayList<>(); for (SmbFile smbFile : smbFiles) { boolean isDirectory = false; try { isDirectory = smbFile.isDirectory(); } catch (SmbException ignore) { } //remove / at the end of the path String smbFileName = smbFile.getName(); smbFileName = smbFileName.endsWith("/") ? smbFileName.substring(0, smbFileName.length() - 1) : smbFileName; fileInfoList.add(new SmbFileInfo(smbFileName, isDirectory)); } return fileInfoList; }
Example 7
Source File: NetworkExplorer.java From jcifs with GNU Lesser General Public License v2.1 | 5 votes |
protected int compareSizes ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { long diff; if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } if ( f1.isDirectory() ) { return f1name.compareToIgnoreCase(f2.getName()); } diff = f1.length() - f2.length(); if ( diff == 0 ) { return f1name.compareToIgnoreCase(f2.getName()); } return diff > 0 ? -1 : 1; }
Example 8
Source File: NetworkExplorer.java From jcifs with GNU Lesser General Public License v2.1 | 5 votes |
protected int compareDates ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } if ( f1.isDirectory() ) { return f1name.compareToIgnoreCase(f2.getName()); } return f1.lastModified() > f2.lastModified() ? -1 : 1; }
Example 9
Source File: NetworkExplorer.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
protected int compareSizes ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { long diff; if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } if ( f1.isDirectory() ) { return f1name.compareToIgnoreCase(f2.getName()); } diff = f1.length() - f2.length(); if ( diff == 0 ) { return f1name.compareToIgnoreCase(f2.getName()); } return diff > 0 ? -1 : 1; }
Example 10
Source File: NetworkExplorer.java From jcifs-ng with GNU Lesser General Public License v2.1 | 5 votes |
protected int compareDates ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } if ( f1.isDirectory() ) { return f1name.compareToIgnoreCase(f2.getName()); } return f1.lastModified() > f2.lastModified() ? -1 : 1; }
Example 11
Source File: JCIFS_NGController.java From DanDanPlayForAndroid with MIT License | 5 votes |
@Override public List<SmbFileInfo> getChildList(String dirName) { List<SmbFileInfo> fileInfoList = new ArrayList<>(); try { mPath += dirName + "/"; SmbFile smbFile = new SmbFile(mAuthUrl + mPath, cifsContext); if (smbFile.isDirectory() && smbFile.canRead()) { fileInfoList.addAll(getFileInfoList(smbFile.listFiles())); } } catch (MalformedURLException | SmbException e) { e.printStackTrace(); } return fileInfoList; }
Example 12
Source File: SMBOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
@Override public SingleCloverURI delete(SingleCloverURI target, DeleteParameters params) throws IOException { URI uri = target.toURI(); SmbFile file = toCannonicalFile(uri); if (uri.toString().endsWith(URIUtils.PATH_SEPARATOR) && !file.isDirectory()) { throw new FileNotFoundException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.not_a_directory"), file)); //$NON-NLS-1$ } if (delete(file, params)) { return createSingleCloverURI(file); } return null; }
Example 13
Source File: JCIFS_NGController.java From DanDanPlayForAndroid with MIT License | 5 votes |
@Override public List<SmbFileInfo> getParentList() { if (isRootDir()) return new ArrayList<>(); List<SmbFileInfo> fileInfoList = new ArrayList<>(); try { //is first directory like smbJ share String parentPath = mPath.substring(0, mPath.length() - 1); int index = parentPath.indexOf("/", 1); //get parent path index int endIndex = parentPath.lastIndexOf("/"); mPath = mPath.substring(0, endIndex) + "/"; if (index == -1) return rootFileList; SmbFile smbFile = new SmbFile(mAuthUrl + mPath, cifsContext); if (smbFile.isDirectory() && smbFile.canRead()) { fileInfoList.addAll(getFileInfoList(smbFile.listFiles())); } } catch (MalformedURLException | SmbException e) { e.printStackTrace(); } return fileInfoList; }
Example 14
Source File: SMBOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
@Override public List<Info> list(SingleCloverURI parent, ListParameters params) throws IOException { URI uri = parent.toURI(); SmbFile file = toCannonicalFile(uri); if (uri.toString().endsWith(URIUtils.PATH_SEPARATOR) && !file.isDirectory()) { throw new FileNotFoundException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.not_a_directory"), file)); //$NON-NLS-1$ } return list(file, params); }
Example 15
Source File: VideoUtils.java From Amphitheatre with Apache License 2.0 | 5 votes |
public static List<SmbFile> getFilesFromDir(String path, NtlmPasswordAuthentication auth) throws Exception { List<SmbFile> results = new ArrayList<SmbFile>(); Set<SmbFile> seen = new LinkedHashSet<SmbFile>(); Deque<SmbFile> queue = new ArrayDeque<SmbFile>(); SmbFile baseDir = new SmbFile(path, auth); queue.add(baseDir); while (!queue.isEmpty()) { SmbFile file = queue.removeFirst(); seen.add(file); if (file.isDirectory()) { Set<SmbFile> smbFiles = new LinkedHashSet<SmbFile>(); Collections.addAll(smbFiles, file.listFiles()); for (SmbFile child : smbFiles) { if (!seen.contains(child)) { queue.add(child); } } } else if (VideoUtils.isVideoFile(file.getName())) { results.add(file); } } return results; }
Example 16
Source File: Samba1FileSystem.java From iaf with Apache License 2.0 | 5 votes |
public boolean isFolder(SmbFile f) throws FileSystemException { try { return f.isDirectory(); } catch (SmbException e) { throw new FileSystemException(e); } }
Example 17
Source File: NetworkExplorer.java From jcifs with GNU Lesser General Public License v2.1 | 4 votes |
protected int compareNames ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } return f1name.compareToIgnoreCase(f2.getName()); }
Example 18
Source File: NetworkExplorer.java From jcifs-ng with GNU Lesser General Public License v2.1 | 4 votes |
protected int compareNames ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException { if ( f1.isDirectory() != f2.isDirectory() ) { return f1.isDirectory() ? -1 : 1; } return f1name.compareToIgnoreCase(f2.getName()); }
Example 19
Source File: SMBOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
private void copyInternal(SmbFile source, SmbFile target, CopyParameters params) throws IOException { if (Thread.currentThread().isInterrupted()) { throw new IOException(FileOperationMessages.getString("IOperationHandler.interrupted")); //$NON-NLS-1$ } source = toCannonicalFile(source); target = toCannonicalFile(target); if (source.equals(target)) { throw new SameFileException(source, target); } boolean makeParents = Boolean.TRUE.equals(params.isMakeParents()); if (source.isDirectory()) { if (!params.isRecursive()) { throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.cannot_copy_directory"), source)); //$NON-NLS-1$ } if (target.exists() && !target.isDirectory()) { throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.cannot_overwrite_not_a_directory"), source, target)); //$NON-NLS-1$ } source = ensureTrailingSlash(source); target = ensureTrailingSlash(target); if (!target.exists()) { try { if (makeParents) { target.mkdirs(); } else { target.mkdir(); } } catch (SmbException e) { throw new IOException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.create_failed"), target), e); //$NON-NLS-1$ } source.copyTo(target); } else { for (SmbFile child: source.listFiles()) { copyInternal(child, new SmbFile(target, child.getName()), params); } } } else { if (target.exists()) { if (params.isNoOverwrite()) { return; } if (params.isUpdate() && (source.lastModified() <= target.lastModified())) { return; } } else if (makeParents) { mkParentDirs(target); } source.copyTo(target); } }
Example 20
Source File: SMBOperationHandler.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
private static List<SmbFile> expand(SmbFile base, String part, boolean directory) throws IOException { if (base == null) { throw new NullPointerException("base"); //$NON-NLS-1$ } if (!base.isDirectory()) { throw new IllegalArgumentException(MessageFormat.format(FileOperationMessages.getString("IOperationHandler.not_a_directory"), base)); //$NON-NLS-1$ } base = ensureTrailingSlash(base); part = URIUtils.urlDecode(part); if (hasWildcards(part)) { SmbFile[] children; try { // Let's use cool SmbFile.listFiles(String) method which resolves exactly our (DOS) wildcards... children = base.listFiles(part); } catch (SmbException e) { // ... but it uses not so cool way of letting know that there are no files matching the pattern if (e.getNtStatus() == NtStatus.NT_STATUS_NO_SUCH_FILE) { return Collections.emptyList(); // maybe this could be done on any SmbException } else { throw e; } } if (!directory) { return Arrays.asList(children); } else { List<SmbFile> dirsOnly = new ArrayList<SmbFile>(children.length); for (SmbFile child : children) { if (child.isDirectory()) { dirsOnly.add(child); } } return dirsOnly; } } else { SmbFile file = new SmbFile(base, part); if (file.exists()) { return Arrays.asList(file); } else { return new ArrayList<SmbFile>(0); } } }