Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have to check if x.csv,y.csv.z.csv etc.. files were present in a path and also have to check if there is any data present in that file.
if file not existed nor daat is not present in any of the file i should throw a message that data or file is not available
You could use the FileSize function to check the file, FileSize(filename).
If the file does not exist it returns Null, if it is empty it returns 0.
An alternative is to use a For - Next loop, like
For each vFile in FileList('c:\<path>\*.csv')
Load *,
'$(vFile)' as FileName,
RecNo() as RecordNo
From "$(vFile)" ... ;
Next vFile
This will loop over all files that match the mask. By looking at FileName and RecordNo you can see where you have your data. It will however not throw any messages...
See also Find My Files.zip
HIC
Do you have a list of files that you want to check?
If you run this, with the first inline load substituted with a load of your file list, you will get a table of each file and the file status.
FileStatus will be 'Missing' if file does not exist, 'Empty' if it's zero-length or 'OK' otherwise.
You won't get any messages, but you could use this table for example to load only OK files (WHERE FileStatus = 'OK') or to show a table with not OK files.
files:
LOAD * INLINE [
file
C:\filepath\exists.csv
C:\filepath\empty.csv
C:\filepath\doesnotexist.csv
];
For each vFile in FieldValueList('file')
FileList:
Load
'$(vFile)' as FileName,
If(IsNull(FileSize('$(vFile)')),'Missing',If(FileSize('$(vFile)')=0,'Empty','OK')) As FileStatus
AutoGenerate 1;
Next vFile
Drop table files;