1ba399b4b8e0a6c60ee0d2d1726d89f7af7004ff
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / utils / FileUtils.java
1 package com.owncloud.android.oc_framework.utils;
2
3 import java.io.File;
4
5 import android.util.Log;
6
7 public class FileUtils {
8
9 public static final String PATH_SEPARATOR = "/";
10
11
12 public static String getParentPath(String remotePath) {
13 String parentPath = new File(remotePath).getParent();
14 parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
15 return parentPath;
16 }
17
18 /**
19 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , : , " , | , ? , *
20 * @param fileName
21 * @return
22 */
23 public static boolean validateName(String fileName, boolean isFolder) {
24 boolean result = true;
25
26 Log.d("FileUtils", "fileName ======= " + fileName);
27 String name = fileName.substring(1);
28 if (isFolder) {
29 name = name.substring(0, name.length() - 1);
30 }
31 if (name.contains("/") || fileName.contains("\\") || fileName.contains("<") ||
32 fileName.contains(">") || fileName.contains(":") || fileName.contains("\"") ||
33 fileName.contains("|") || fileName.contains("?") || fileName.contains("*")) {
34 result = false;
35 }
36 return result;
37 }
38 }