Search : in
By :

Creating new folders and moving,renaimg files

Last answer on Aug 27, 2009 5:53:26 pm BST swampdonkey, on Sep 15, 2008 3:12:22 am BST 
 Report this message to moderators

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!

Configuration: Windows XP
Firefox 3.0.1

1

platinump2, on Sep 15, 2008 10:13:14 am BST
  • +6

Will you use the system on a network or something like that?

Reply to platinump2

2

swampdonkey, on Sep 17, 2008 4:21:52 am BST
  • +2

I will copy it off the network onto an external harddrive.

Reply to swampdonkey

9

raisalvador, on May 13, 2009 8:32:57 am BST
  • +10

/*
* 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();
}
}

}

Reply to raisalvador

3

bigd519, on Jan 17, 2009 4:44:19 am GMT

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.

Reply to bigd519

4

pasaway, on Jan 23, 2009 9:13:21 pm GMT

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

Reply to pasaway

5

Bert, on Jan 26, 2009 11:20:45 pm GMT
  • +1

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!

Reply to Bert

6

marinegundoctr, on Feb 8, 2009 7:49:29 pm GMT

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.

Reply to marinegundoctr

7

raisalvador, on Mar 4, 2009 10:01:16 am GMT
  • +1

I would suggest doing it in java... need help.. i could send a custom software to do it... call me +639268919248

Reply to raisalvador

8

raisalvador, on Mar 13, 2009 6:22:31 am GMT
  • +2

Is the request still active.... before i post the java code?

Reply to raisalvador

10

 blackpete, on Aug 27, 2009 5:53:26 pm BST

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!

Reply to blackpete