Question

I have a Java code that transfers file from FTP on Mainframe to my local system . The problem is how do I tell if the given path is a file or folder ? I cannot use the check for extensions as i don't know what the possible extensions can be . Also the following code always returns false ,

 fileSystem.isFile("fileName");

Being a mainframe filesystem , the path is seperated by . instead of / and hence a check for . at the end also doesnt work.

Again I stream data from the input path to output location using

url="connection url of the mainframe"
bufferedInputStream = new BufferedInputStream(url.getInputStream());

When I have files at the source path , it writes the content of the file to the destination , and when the source path has a directory it writes the the names and other properties of the files at the directory to the destination.

Sample output when the source is a directory is

Name    VV.MM   Created       Changed          Size  Init    Mod    Id
QQQQ    01.00  2009/12/18   2009/12/18 12:15    18    18     0    XXXX 
RRRR    01.00  2009/12/18   2009/12/18 12:16     19     19    0  XXXXX

How do I determine if the source path is a file or folder ?

Was it helpful?

Solution 2

I found a way to determine if the path on mainframe is a file or PDS (analogically a directory ) . I used org.apache.hadoop.fs.ftp.FTPFileSystem library and the following snippet would work by returning the list of files .

FTPFile[] files = ftp.listFiles(); 

Looping through the files and checking file1.isFile() would suffice. Again remember to change to the current working directory before listing the files using ftp.cwd(inputPath);

For an explanation on Mainframe file system please refer to Bruce Martin's answer and the comments that follow. .

OTHER TIPS

I do not have an answer but it sounds like you are acessing Zos. For those who do not know anything anything about Zos

  • Zos Does not have directories
  • What he is calling a directory is probably a PDS (see PDS in Dataset). For those not from a mainframe background, think of it as a type of archive (i.e. jar, Tar, zip etc). This is not a completely accurate description, PDS have some limitations & uses jar files do not, but a jar file is the closest analogy in the PC, *NIX world I can think of.

  • How do you detect them - not sure, there may be an file attribute you can access

You don't say what version of java you are using or if you're using a special library for the host filesystem.

Can you use java.io.File#isDirectory() instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top