* Due to the Zhang Xiaoxiang -7k monthly salary of one of the cracks _ Traffic light Management System Video Tutorials folder video files are stored in each sub-folder
* Requirements: All video files are moved to Zhang Xiaoxiang -7k monthly salary of one of the test cracked _ Traffic light Management System Video Tutorial folder deleted subfolders of the original video
Public class movefiles {public static void main (String[] args) {// todo auto-generated method stubfile f = new file ("D:\\ Baiduyundownload\\ Zhang Xiaoxiang -7k One of the monthly salary test, traffic light Management system Video Tutorial ");//file f = new file (" d:\\baiduyundownload\ \ Preach Wisdom Podcast _ Zhang Xiaoxiang _java Multi-threading and concurrent Library advanced application video tutorial Download ");if (F.exists ()) MoveFiles2 (F, f.getpath ()); System.out.println ("Done");} Public static void movefiles (File f, string path) {File[] files = f.listfiles (); string addname = "";// first determine if the name of the folder contains "_ Traffic", and then in get the corner mark Otherwise indexof will return-1 appears substring (-1) with Exception if (F.getname (). Contains ("_ Traffic")) {int index = F.getname (). IndexOf ("_ Traffic");//int index = f.getname (). IndexOf ("Xiang _") +1;addname = F.getname (). substring (index);} for (file file : files) {if (File.isdirectory ()) moveFiles (File, path); else {if&nBSP; (File.getname (). EndsWith (". avi")) {file dest = new file (Path, file.getname () . replace (".",addname + ".")); File.renameto (dest); System.out.println (Dest.getname ());} elsefile.delete ();// Delete redundant files}file.delete ();// Delete empty folders}}// If you need to keep folders that do not contain "_ Traffic" The code is as follows Public static void movefiles2 (File f, string path) {File[] files = f.listfiles (); Int index = f.getname (). IndexOf ("_ Traffic"); String addname = f.getname (). substring (index);for (file file : files) {System.out.println (File.getname ());if (File.isdirectory ()) if (File.getname (). Contains ("_ Traffic"))// In this case, it is guaranteed that// each F object except the outermost file contains "_ Traffic" MoveFiles (File, path);else {if (File.getname (). EndsWith (". avi")) {file dest = new file (Path, file.getname (). Replace (".", AddName + ".")); File.renameto (dest);// system.out.printlN ("Generate:" +dest.getname ());} else {system.out.println (File.delete () + ". The deleted file is. " + file.getname ());// Delete redundant files}}// Delete empty folders returns True if and only if files or directories are deleted successfully Otherwise, return FalseSystem.out.println (File.delete () + ", delete the folder is:" + file.getname ());}}
This article comes from "either desperately, or roll back!" "Blog, be sure to keep this provenance http://jiangzuun2014.blog.51cto.com/8732469/1532184