Creating new folders and moving,renaimg files

Closed
swampdonkey
Posts
1
Registration date
Sunday September 14, 2008
Status
Member
Last seen
September 14, 2008
- Sep 14, 2008 at 10:12 PM
 Arun - Oct 27, 2011 at 05:07 PM
Hello,

I need some with a code to help create 4,000 folders (1,000 dir, 3,000 sub dir) then move and rename over 35,000 files. I have a list of old paths and new paths in an Access 2003 db. They will also need to be moved from different network drives. Can anyone help?

Thanks in advance!

7 replies

platinump2
Posts
10
Registration date
Thursday May 15, 2008
Status
Member
Last seen
October 18, 2008
7
Sep 15, 2008 at 05:13 AM
will you use the system on a network or something like that?
7
I will copy it off the network onto an external harddrive.
0
raisalvador > swampdonkey
May 13, 2009 at 03:32 AM
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package maintenance;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
*
* @author ryan.o.salvador
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
String src = "D:\\try";
File source = new File(src);
if(!source.exists()){
System.out.println("File or directory does not exist.");
System.exit(0);
}
String dest = "C:\\try";
File destination = new File(dest);
if(!destination.exists()){
System.out.println("destination dir doesnt exists");
destination.mkdir();

}
copyDirectory(source, destination);



}
private static void copyDirectory(File sourceDir, File destDir) throws IOException{
System.out.println("Copying directory");

File[] children = sourceDir.listFiles();
System.out.println(destDir +" exists:"+destDir.exists());
if(!destDir.exists()){
destDir.mkdir();
System.out.println("destination dir:"+destDir);
}
for(File sourceChild:children){
//System.out.println(sourceChild.getName());
String name = sourceChild.getName();
System.out.println("Filename:"+name);
File destChild = new File(destDir,name);
if(sourceChild.isDirectory()){
System.out.println("test sourceChild"+sourceChild.isDirectory());
copyDirectory(sourceChild, destChild);
}
else{
copyFile(sourceChild, destChild);
}

}
}
private static void copyFile(File source, File dest) throws IOException{
if(!dest.exists()){
System.out.println("dest:"+dest);
dest.createNewFile();
}
System.out.println("Writing file :"+source.getPath()+" to: "+dest.getPath());

InputStream in = null;
OutputStream out = null;
try{

in = new FileInputStream(source);
out = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int len;
while((len=in.read(buf))>0){
out.write(buf, 0, len);
}
}
finally{
in.close();
out.close();
}
}

}
0
Good job..Thank you
0
is the request still active.... before i post the java code?
4
First, create folders called, documents, pictures, power points, excel, movies, music. then move all the doc to the folder document, all the photos to the folder pictures and so on. leaving the desktop or wherever you run the program organized.

The program can ask first to create a folder name, then the command to move what files to that directory.

Good luck!
3
I dont think there is any commercially available software to do it.

The only way in theory to do it MAYBE is to create a batch file which is basically an automated script. you can do this in notepad.

If you dont know how to create batch files theres not much point in trying to learn as you need to learn alot of program line commands and it would take forever



maybe sort the file types? and then set up directories?

good luck.
0
if you need an automatic program to move from the old folders to the new folders based on your access DB contents I think that unfortunately the only way is as said our friend before to write a script.
However if you can not write ths kind of stuff, you could be helped using "the rename" tool (freeware), that will allow you to rename folders and files in a mass update mode.
So if there is a logic in the job you want to accomplish, "therename" can be of a great help
0
Bert > pasaway
Jan 26, 2009 at 06:20 PM
I would suggest TotalComander it is freeware and will move entire File Tree's from one location to another (whilst maintaining permissions/structure etc) and then the renaming you may have to do manually at the other end? I'm sure you have your reasons for wanting to rename a thousand directories ... but this is by far the easiest way to move the file structure!
0

Didn't find the answer you are looking for?

Ask a question
marinegundoctr
Feb 8, 2009 at 02:49 PM
I would use ICE Mirror (free software) to mirror the existing directory structure to the new drive, then use something like (my favorite) FlashRenamer to do the renaming. It can rename directories, filenames, extensions, and even allow you to set up a batch script. It has a good help file with all of the scripting commands it uses. Very adaptable. Your best bet is going to be doing this in steps rather than copy and rename unattended.
0
I would suggest doing it in java... need help.. i could send a custom software to do it... call me +639268919248
-4
uhhhh... i have been making bacth file "fake" viruses to see if i can do it and most of them come out like the snapshot in the tuiturails.
-6