Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have some issue with a FOR EACH loop. It's not the first time I use it, but I guess it's some stupid little mistake.
I will just post my code here.
The issue is, in this directory there's files in .xls format and some in .xlsx format, so I guess I will need two loops. The first one should go after the .xlsx files - but apparently, nothing is found to match, the loop is simply skipped.
DIRECTORY ''; // In this directory, there should be 2 files with the ending .xlsx;
// The file_path is correct, I have tested it.
SET v_Filemask = 'Staplerliste*.xlsx';
FOR EACH v_File IN FileList ('$(v_Filemask)')
Hilfstab_pre:
FIRST 1 LOAD
FileName() as Dateiname
From
$(v_File) (ooxml, no labels);
NEXT v_File
Can anyone spot the error here?
Thanks a lot!
Best regards,
DataNibbler
Hi
Looks OK to me, except possibly for the (unnecessary) decoration in the DIRECTORY line (the square brackets and quotes are not required). If the XLS loop works using the same logic, then that is probably not the problem.
HTH
Jonathan
Hi DataNibbler,
I assume that filelist need a fullpath and didn't regognize a directory-statement.
- Marcus
Try replacing the variable with:
FOR EACH v_File IN FileList ('S:\Common\31 Maintenance\Stapler\Staplerliste*.xlsx')
or use one of the known filenames to test (ie not using wildcards)
Your From statement should read:
From [$(vFile)]
as their is a space in the path name.
Jonathan
Edit = I think Marcus is correct
Hi Marcus,
that is a valid assumption - but no, it doesn't. I have several other FOR EACH loops where I use the DIRECTORY and then a filelist which only holds the filename itself.
I will look for another way to do this.
It is possible to use the * just for the middle part of a file_name and specify something at the end, isn't it
(like >> Staplerliste*(Master) <<)
to rule out files that have something more behind that > (Master) < in the file_name.
Best regards,
DataNibbler
In general it should work - I guess there is a small syntax issue, maybe with the directory and/or the variable-staement, try to trace the path to see what is wrong. This for example worked:
Sub DoDir(Root)
for each Ext in 'qvw', 'qvd' //, 'qvo', 'qvs', 'qvt', 'txt', 'csv', 'xls', 'xlsx'
for each File in filelist (Root&'\*.'&Ext)
.....
- Marcus