
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Loop through subfolders and generate a output file for each
Hi folks,
I've a small requirement to loop through the files in a sub folder and generate a output file for each folder.
As shown above, I need to load all the files under Australia folder , generate a concatenated table and store it into a csv. And it should loop through India, UK, USA folders......
Pls can you suggest a way to achieve this?
Many Thanks in Advance!
- « Previous Replies
-
- 1
- 2
- Next Replies »
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It´s pretty simple
- for Each dir in DirList('yourpathgoeshere')
- for Each file in FileList('$(dir)\*.csv') // or .txt
- if filesize('$(file)') > 0 then
- tmp:
- LOAD *
- FROM
- [$(file)](txt, codepage is 1252, no labels, delimiter is ',', msq);
- end if
- next;
- store tmp into [$(dir).csv](txt);
- drop table tmp;
- next

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This should work
for Each dir in DirList('yourpathgoeshere')
for Each file in FileList('$(dir)\*.csv') // or .txt
tmp:
LOAD *
FROM
[$(file)](txt, codepage is 1252, no labels, delimiter is ',', msq);
next;
store tmp into [$(dir).csv](txt);
drop table tmp;
next

.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use a For-Next loop, e.g.
For each vFileName in Filelist ('C:\Path\*.txt')
Load *,
'$(vFileName)' as FileName
From [$(vFileName)];
Next vFileName
See more on Loops in the Script
HIC

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what kind of files you have in folders?. qvd or excels?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DIRECTORY;
FOR Each Dir in 'Australia', 'India', 'UK', 'USA'
trace Dir=$(Dir);
Concat='';
FOR Each File in filelist ('$(Dir)\*.qvd')
Trace File=$(File);
Table_$(Dir):
$(Concat)
load * from [$(File)] (qvd);
Concat=' concatenate ';
NEXT File;
STORE Table_$(Dir) into Table_$(Dir).csv (txt);
DROP Table Table_$(Dir);
NEXT Dir;
edit: added the bold

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I've to load excel (xlsx) files and I modified the codes sent with xlsx and it doesn't work.
Hi Clever,Henric, Maxximo
The script doesn't generate any table.
Thank for your quick response!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Would you mind posting your script here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you have single sheet in excel or multiple sheets?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for Each dir in DirList('C:\Data Uploads')
for Each file in FileList('$(dir)\*.xlsx')
tmp:
LOAD *
FROM
[$(file)](ooxml, embedded labels, table is [Input file]);
next;
store tmp into [$(dir).csv](txt);
drop table tmp;
next

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
for Each dir in DirList('C:\Data Uploads\*.*') // Try this
for Each file in FileList('$(dir)\*.xlsx')
tmp:
LOAD *
FROM
[$(file)](ooxml, embedded labels, table is [Input file]);
next;
store tmp into [$(dir).csv](txt);
drop table tmp;
next

- « Previous Replies
-
- 1
- 2
- Next Replies »