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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
louisernould
Contributor III
Contributor III

Load a file in the last folder

Hello everybody,

I have a new problem and I think you guys will be able to solve it with me.

I have one folder (name: extract) , which is full of monthly extractions (names: 201407,201408,201409,...). In each folder, I have one file (name: Product.csv) and I want to select the file 'product' in the last folder (the new one) each month.

So, I want my script like that:

LOAD

@1

@2

@3

@4

from ['The file Product.csv from the last folder']

I tried something else with:

for each File in filelist ('G:Extract\*') But I don't know how to select the last folder...

If someone knows how to solve it... and wants to help a poor newbee 

Thanks

Louis

1 Solution

Accepted Solutions
demoustier
Creator
Creator

or:

Step 2:

FOLDER_table:

load

right(dirname,len(dirname)-Index(dirname,'\',-1)) as folder_name Resident DIRNAME;

folder_list:

NoConcatenate

LOAD folder_name Resident FOLDER_table Order BY folder_name;

drop Table FOLDER_table;

and you should have now the list of your folder order by asc.

You chosse the last one by peek function in a variable and use the variable in your Load* from...

but not sure it's works. depending your folder_name list....

View solution in original post

12 Replies
demoustier
Creator
Creator

Hi !

What is the rule nominating all your folder ?

How can we recognize the last folder: by his name ? his date ?

can you post a picture of your folder tree ?

marcus_sommer

Beside filelist you could use dirlist to read folders and sub-folders - have a look in help by "for each ...".

- Marcus

louisernould
Contributor III
Contributor III
Author

hey Demoustier !


A tree is a good idea, but here is an explanation:

G:\Extract --201406-- file1.txt / file2.txt / Product.csv

                 --201407-- file1.txt / file2.txt / Product.csv

                 --201409-- file1.txt / file2.txt / Product.csv

                 --2014010-- file1.txt / file2.txt / Product.csv

For me, the newest is 201410 (october 2014) ans I want to load the file 'Product.csv' of the newest folder

Is it enough for you ?

demoustier
Creator
Creator

OK.

Let's try 🙂

Could you try following script:

SUB DoDir(Root)

FOR each   File in filelist (Root&'\*Product*'&'.csv')

FOR each Dir2 in dirlist (Root&'\*')

DIRNAME:

load

'$(Dir2)' as dirname

autogenerate 1;

CALL DoDir(Dir2)

Next File

NEXT Dir2

END SUB

CALL DoDir('G:\Extract')

it should return all folder adress in G where a .csv have Product in the name...

Does this step works ?

PS: I missed the red line in my first post

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Something like this:

Temp:

load '' as DirName

AutoGenerate(0);

for each Dir in DirList('G:\Extract\*')

  SET vDir = $(Dir);

  Concatenate(Temp)

  load num(SubField('$(vDir)','\',-1)) as DirName AutoGenerate(1);

next Dir

Temp2:

LOAD max(DirName) as LastDir

Resident Temp;

drop Table Temp;

LET vLastDir = peek('LastDir');

drop Table Temp2;

Result:

LOAD * FROM (txt, utf8, embedded labels, delimiter is ',', msq);


talk is cheap, supply exceeds demand
louisernould
Contributor III
Contributor III
Author

Ok this step works !

Sorry It's quite long ^^ and I needed to modify the script:

...

CALL DoDir(Dir2)

Next File

NEXT Dir2

Next File

END SUB

...

And It's good for now

louisernould
Contributor III
Contributor III
Author

Hi Gysbert !

Actually your solution gives to me a table with all the files in the subfolders (file1.txt, file2.txt and Product.csv)

I want only the newest product 

demoustier
Creator
Creator

2nd step:....use Gysbert solution !!! he's level 11 !!!!!!

next step depending of your 'dirname' list. could you give some result

louisernould
Contributor III
Contributor III
Author

ahahah ok good team job !

I try that !