1. ## [SOLVED] Folder Watching

Hi Folks,

I am having some files(.txt) in a directory called as Unprocessed folder,i would like to take one by one file and send it to the processing path say it as..C:\processingfolder
Each time when an UnprocessFolder get any new file it should be sent to the processing folder.

-jazz

2. Have u started with itatleast getting .txt files from a directory?
Rest would be next step, Do it step by step and in a simple way.

3. yeah i am able to List the content of a folder...but the main prob is to pick up the file from the folder...

suggest some ideas..

-jazz

4. pick up the file
Does that mean moving the file from one directory to another?
One way would be to copy the file from one directory to the other and then deleting the file from the one directory.

5. Ur Right...it need to copy from the folder and send it to another path:cool:
If any new file comes into the Source folder it should be copied to the Dest Folder

6. Is this what u wanted?

Java Code:
public static void copy(File source, File dest) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(dest));

}

br.close();
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

7. ## Copy file into different folder and get the file created time

Here is the code

Java Code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

public class copyFiles {

public static void copy(File source, File dest) {

File cpDestFile = null;
try {
if (dest.isDirectory()) {
if (source.isFile()) {
System.out.println("File name = " + source.getName());
System.out.println("File name dest = " + dest.getPath());
System.out.println("File name cpDestFile = "
+ dest.getPath() + File.separator
+ source.getName());
cpDestFile = new File(dest.getPath() + File.separator
+ source.getName());

} else {
return;
}
}
BufferedWriter bw = new BufferedWriter(new FileWriter(cpDestFile));
}
br.close();
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String args[]) {
copyFiles fcpy = new copyFiles();
File cpSrcFile = new File("D:\\Unprocessed_folder\\text1.txt");
File cpDestDir = new File("D:\\processingfolder");
fcpy.copy(cpSrcFile, cpDestDir);

}
}
and check if any file has been created after a specific time which u need to store in some variable and compare it with file created time with the following code and then copy it into ur destination folder.

Java Code:
file = "C:\\yourFile.txt";
try
{ //NOTE FILES MUST NOT HAVE SPACES IN THE NAMES OTHERWISE THIS DONT WORK!
Process ls_proc = Runtime.getRuntime().exec("cmd.exe /c dir " + getFilePath() + " /tc");
DataInputStream in = new DataInputStream(ls_proc.getInputStream());
for (int i = 0; i < 5; i++ )
{
}
StringTokenizer st = new StringTokenizer(stuff);
String dateC = st.nextToken();
String timeC = st.nextToken();//TIME CREATED
in.close();
}
catch (IOException e1)
{
System.out.println("Error in getting create time");
}

8. Solved
Thanks for ur time and support..

-Jazz

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•