Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a script that reads files from a directory, like:
c:\data\charges.*
This folder may or may not have data in it, and I don't know exactly what the file name is, so FileSize won't work -- I mean, I can't do FIleSize("charges.*"), can I?
I can't see a function where I can feed it a file path and it'll come back with the number of files. Has anyone found a solution for this?
Thanks.
ok, try this script
For each file in dirlist ('c:\data\*');
Files:
Load '$(file)' as File autogenerate(1);
next Let NoOfFiles = NoOfRows('Files'); //This will return he n° of files
or this
Set NoOfFiles = 0;
For each file in dirlist (''c:\data\*');
Let NoOfFiles = NoOfFiles + 1; //This will return he n° of files
next
so, then you can do
if NoOfFiles > 0 then load .... else exit script end if
maybe you can try with Set ErrorMode = 0 too
rgds
hi, try filename() and filesize() just like here, without parameters, they will return the value for each of your charges* files
rgds
PD. by the way, you can use these functions to create columns, like filename() as file_name
Sorry, I didn't make myself clear before. What I'm trying to do is see if the folder has anything in it, and if not, I want to exit script to avoid an error that arises when there aren't any files in the folder.
So, filename() and filesize() won't work because there aren't any files to be found.
ok, try this script
For each file in dirlist ('c:\data\*');
Files:
Load '$(file)' as File autogenerate(1);
next Let NoOfFiles = NoOfRows('Files'); //This will return he n° of files
or this
Set NoOfFiles = 0;
For each file in dirlist (''c:\data\*');
Let NoOfFiles = NoOfFiles + 1; //This will return he n° of files
next
so, then you can do
if NoOfFiles > 0 then load .... else exit script end if
maybe you can try with Set ErrorMode = 0 too
rgds
Thanks, Héctor. I needed to use filelist instead of dirlist, but this worked just right.
Hi Hector Munoz,
I am trying which is very similar to your post.
But the difference is i need to check whether any Text Files are there or not ?
If any Text Files are present in that folder then variable VData =1 or
If no Text Files are present in that folder then set variable VData =0.
How i can work on this ?
Thanks in advance.
Regards
Venkat
Hi Hector,
your second solution, with "filelist" instead of "dirlist" it works perfectly, also without Set ErrorMode = 0.
Many thanks,
Giulio