-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPathname.java
More file actions
executable file
·73 lines (60 loc) · 1.58 KB
/
Copy pathPathname.java
File metadata and controls
executable file
·73 lines (60 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
public class Pathname
{
/* Returns 4 components:
* [0] - directory
* [1] - filename
* [2] - filename-base (excluding the dot)
* [3] - filename-ext (including the dot)
*/
public static String[] splitPath(String s)
{
String a = s;
String[] final_string = new String[4];
int last_occur = 0;
for (int i = a.length()-1; i >= 0; i--)
{
if(a.charAt(i) == '/')
{
last_occur = i;
break;
}
}
if(a.contains("."))
{
final_string[0] = a.substring(0,last_occur+1);
final_string[1] = a.substring(last_occur+1);
final_string[2] = a.substring(last_occur+1, a.length()-4);
final_string[3] = a.substring(a.length()-4,a.length());
}
else
{
final_string[0] = a.substring(0,last_occur+1);
final_string[1] = a.substring(last_occur+1);
final_string[2] = a.substring(last_occur+1);
final_string[3] = "";
}
return final_string;
}
public static String ensureAbsolute(String path)
{
String curDir = System.getProperty("user.dir");
String long_name = curDir + "/" + path;
if(path.charAt(0) == '/')
return path;
else return long_name;
}
public static void main(String args[])
{
String[] final_string_main = new String[4];
for (String s: args)
{
String a = ensureAbsolute(s);
final_string_main = splitPath(a);
if(s.contains("."))
{
System.out.println("File: " + final_string_main[1] + " Type: " + final_string_main[3] + " [" + final_string_main[0] + "]");
}
else System.out.println("File: " + final_string_main[1] + " [" + final_string_main[0] + "]");
}
}
}