Disk Space

Highlighted
Six Stars

Disk Space

Hi Team

 

Using Talend Job i want to find out what is free disk space available in in PC

I cmd prompt  in have used the following command to get it dir c:\

When i execute the same in tsystem component i am getting the path of  Talend root directory

Is their any to find it out

Please help me a bit urgent

 

Thanks In advance

Saranya


Accepted Solutions
Sixteen Stars

Re: Disk Space

I always the tSystem quite cumbersome so only use it when I really have to. In this case, you can actually use a simple bit of Java to get this. Have a play around with the following code in a tJava to see how it works, then move it to a tJavaFlex to return the data in a row....

 

Imports

import java.text.NumberFormat;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.FileStore;
import java.nio.file.Path;
import java.io.IOException;

Code

NumberFormat nf = NumberFormat.getNumberInstance();
for (Path root : FileSystems.getDefault().getRootDirectories()) {

    System.out.print(root + ": ");
    try {
        FileStore store = Files.getFileStore(root);
        System.out.println("available=" + nf.format(store.getUsableSpace())
                            + ", total=" + nf.format(store.getTotalSpace()));
    } catch (IOException e) {
        System.out.println("error querying space: " + e.toString());
    }
}

FYI I borrowed this code from here (https://stackoverflow.com/questions/1051295/how-to-find-how-much-disk-space-is-left-using-java). In order to use it in a tJavaFlex, put the code up to the start of the for loop in the Start Code, the rest (apart from the last "}") in the Main Code and the last "}" in the End Code. You can return your disk space data in the Main Code section by creating columns to do this.


All Replies
Sixteen Stars

Re: Disk Space

I always the tSystem quite cumbersome so only use it when I really have to. In this case, you can actually use a simple bit of Java to get this. Have a play around with the following code in a tJava to see how it works, then move it to a tJavaFlex to return the data in a row....

 

Imports

import java.text.NumberFormat;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.FileStore;
import java.nio.file.Path;
import java.io.IOException;

Code

NumberFormat nf = NumberFormat.getNumberInstance();
for (Path root : FileSystems.getDefault().getRootDirectories()) {

    System.out.print(root + ": ");
    try {
        FileStore store = Files.getFileStore(root);
        System.out.println("available=" + nf.format(store.getUsableSpace())
                            + ", total=" + nf.format(store.getTotalSpace()));
    } catch (IOException e) {
        System.out.println("error querying space: " + e.toString());
    }
}

FYI I borrowed this code from here (https://stackoverflow.com/questions/1051295/how-to-find-how-much-disk-space-is-left-using-java). In order to use it in a tJavaFlex, put the code up to the start of the for loop in the Start Code, the rest (apart from the last "}") in the Main Code and the last "}" in the End Code. You can return your disk space data in the Main Code section by creating columns to do this.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.