Disk Space

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
Community Manager

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
Community Manager

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.

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog