-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path203. Remove Linked List Elements.java
39 lines (33 loc) · 1.29 KB
/
203. Remove Linked List Elements.java
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
import java.io.File;
import java.io.IOException;
public class rename
{
public static void main(String[] argv) throws IOException
{
// Path of folder where files are located
String folder_path =
"C:\\Users\\Anannya Uberoi\\Desktop\\myfolder";
// creating new folder
File myfolder = new File(folder_path);
File[] file_array = myfolder.listFiles();
for (int i = 0; i < file_array.length; i++)
{
if (file_array[i].isFile())
{
File myfile = new File(folder_path +
"\\" + file_array[i].getName());
String long_file_name = file_array[i].getName();
String[] tokens = long_file_name.split("\\s");
String new_file_name = tokens[1];
System.out.println(long_file_name);
System.out.print(new_file_name);
// file name format: "Snapshot 11 (12-05-2017 11-57).png"
// To Shorten it to "11.png", get the substring which
// starts after the first space character in the long
// _file_name.
myfile.renameTo(new File(folder_path +
"\\" + new_file_name + ".png"));
}
}
}
}