aspose file tools
The moose likes Java in General and the fly likes Not able to retrieve files name s from a folder Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Not able to retrieve files name s from a folder" Watch "Not able to retrieve files name s from a folder" New topic
Author

Not able to retrieve files name s from a folder

Vishnu Murthy
Ranch Hand

Joined: Jan 04, 2001
Posts: 56
Hi,
I am trying to retrieve all the file names( including files in the sub folder) present in the given path.

It is working fine if the given path is present on my system. But if the path is a remote machine path then I am not able to retrive any files though I have got full permission on the given remote path.

I have written the method as follows. can some help me regarding this problem.





import java.io.*;
import java.lang.String;
import java.io.File;
import java.util.*;
import java.util.List;
import java.lang.*;

public class FilecheckTest
{
public static void main(String args[])
{
File file_mem = new File("C:\\QRPDSTestCases");// this is working

//File file_mem = new File("\\son1415\\Memory"); // this is not working

Map mapfiles = new HashMap();
showFiles(file_mem, mapfiles);

Iterator iterator_mapfiles = mapfiles.keySet().iterator();
while(iterator_mapfiles.hasNext())
{
String fpath= (String)iterator_mapfiles.next();
String fname= (String)mapfiles.get(fpath);

System.out.println(fname);
System.out.println(fpath);
}
}



//getting file name and url
public static Map showFiles(File file, Map mapfiles)
{
File[] files = file.listFiles();
if(file.isDirectory())
{
for(int i=0;i<files.length; i++)
{
showFiles(files[i], mapfiles);
}
}
else
{
String path = file.getPath();
String name = file.getName();
mapfiles.put(path,name);
}
return mapfiles;
}
}


Thanks
Vishnu
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Vishnu Murthy, it is not working at my end too.

But I just mapped the remote location with the drive name and it worked.

This can be a work around, if it solves you problem.


My blood is tested +ve for Java.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Have you tried two escaped backslashes? eg "\\\\machinename"
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Originally posted by David O'Meara:
Have you tried two escaped backslashes? eg "\\\\machinename"


David, It' working my end.

Thx
Vishnu Murthy
Ranch Hand

Joined: Jan 04, 2001
Posts: 56
David, It' working my end also

Thanks
Vishnu
Agapios Hartzoulakis
Greenhorn

Joined: Oct 13, 2005
Posts: 17
Could i add a question to the above subject?
What if i don't have full permission on the given remote path? What change must be done?
Thanks
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
I believe you don’t required “full permission” to read any file remotely using java. You just need “read permission”.
JuanP barbancho
Ranch Hand

Joined: Oct 25, 2005
Posts: 52
Hi,

Try to use / instead of \\

Thanks
Agapios Hartzoulakis
Greenhorn

Joined: Oct 13, 2005
Posts: 17
I didn't explain my question well. I mean that a password is required from the system (Windows) to let me access the files in the remote system. Thanks
JuanP barbancho
Ranch Hand

Joined: Oct 25, 2005
Posts: 52
Hi,

You could use a jakarta API for access to remote windows system.

Thanks
 
I agree. Here's the link: jrebel
 
subject: Not able to retrieve files name s from a folder
 
Similar Threads
how to read files from remote system
File listing not working in Tomcat
Write a program that reads and writes from binary or text files
how to access remote files
Retrieving specific file names under given path