Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need to check whether folder contains Text files or not

Hi all,

I have a script that reads files from a directory, like:

c:\data\charges\*.txt

This folder may or may not have data in it, and I don't know exactly whether the files are having or not.

Now if there is a text files in that folder then i need to have a VData = 1 or

       if there is no text files in that folder then i need to have a VData = 0.

Can anyone find this solution ?

Thanks in advance.

Regards

venkat

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Ah, yes, of course.

I think you already found the other thread, so why not use as suggested:

Set NoOfFiles = 0;

For each file in filelist ('C:\data\charges\*.txt');

Let NoOfFiles = NoOfFiles + 1; //This will return he n° of files

next

and then

set VData if NoOfFiles >0

??

View solution in original post

6 Replies
swuehl
MVP
MVP

You could use something like a temporary table

tmpTable:

LOAD FileName() as FileName

FROM

and  then count the records.

Edit:

This could look like

if(NoOfRows('tmpTable') >0) then

     Let VData=1;

else

      let VData=0;

end if

edited by  swuehl

Not applicable
Author

Hi swuehl,

Thanks for your reply,

What i am trying to do is,

In a particular if Text Files are present then i need to set a variable VData = 1 or

if no Text Files are present then i need to set a variable VData = 0.

I hope so you understand what i am trying ?

Thanks in advance

Regards

Venkat

swuehl
MVP
MVP

Yes, I think I understood.

I am trying to build a temporary table with an entry for each text file.

Then (please note my edit above), I check if the count of rows are >0 and set the variable accordingly.

Oh, I probably should

drop table tmpTable;

afterwards.

I think it should work, without trying it.

Regards,

Stefan

Not applicable
Author

Hi ,

If no text files in that folder, then it is creating an error When Loading the script.

It should not generate an error when loading if no text files in a folder.

Regards

venkat

swuehl
MVP
MVP

Ah, yes, of course.

I think you already found the other thread, so why not use as suggested:

Set NoOfFiles = 0;

For each file in filelist ('C:\data\charges\*.txt');

Let NoOfFiles = NoOfFiles + 1; //This will return he n° of files

next

and then

set VData if NoOfFiles >0

??

Not applicable
Author

Hi Swuehl,

Thanks it working fine. The code is really simple and good.

Thanks once again.

Regarads

Venkat