<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Load data from the highest folder number in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582662#M598042</link>
    <description>&lt;P&gt;Thanks so much Tim, I'll try this and let you know.&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
    <pubDate>Tue, 21 May 2019 10:36:24 GMT</pubDate>
    <dc:creator>davidthorpester</dc:creator>
    <dc:date>2019-05-21T10:36:24Z</dc:date>
    <item>
      <title>Load data from the highest folder number</title>
      <link>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582309#M598040</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have data I want to load that gets stored in hourly folders. I want to load the latest hours worth of data.&lt;/P&gt;&lt;P&gt;File example (for 4am on 10th May): root\results\20190510\04\file.qvd&lt;/P&gt;&lt;P&gt;Even though there is a folder for every hour, not all hours dump a file. So I would like to load the latest file for that day. I hope this made sense! Is it possible to look in multiple folders for the latest file? or take the max folder number that has a file?&lt;/P&gt;&lt;P&gt;Thanks, David&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 15:23:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582309#M598040</guid>
      <dc:creator>davidthorpester</dc:creator>
      <dc:date>2019-05-20T15:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Load data from the highest folder number</title>
      <link>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582639#M598041</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;here is a script for you. Maybe you need to adapt it to your needs.&lt;/P&gt;&lt;P&gt;Change the vPath to your Folder you want to scan. Note that if your select your Root Folder it will scan the subfolders too.&lt;/P&gt;&lt;P&gt;The script will scan all Folders and get the FilePath for each file.&lt;/P&gt;&lt;P&gt;Then it will choose the latest file and load only that.&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;tim&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;//**********************************************************************************
//Scan current Folder &amp;amp; Subs
SUB doDir (dir)
	FOR EACH file in filelist('$(dir)' &amp;amp;  '\*.qvd') ;	
		FileName:
		first 1
		Load FilePath() as FilePath,
			 Subfield(FilePath(), '\', -3) as YYYYMMDD,
			 Subfield(FilePath(), '\', -2) as HH,
			 num(Subfield(FilePath(), '\', -3) &amp;amp; Subfield(FilePath(), '\', -2)) as CheckNumber
		FROM '$(file)';
	NEXT file
		
	// Process subdirectories
	FOR EACH subdir in dirlist( '$(dir)' &amp;amp; '\*' )
  		CALL doDir('$(subdir)')
	NEXT subdir
END SUB

//**********************************************************************************
//scan Root Folder
SUB doRoot (root)
	FOR EACH subdir in dirlist( '$(root)' )
	  CALL doDir('$(subdir)')
	NEXT subdir
END SUB

//**********************************************************************************
LET vPath = 'root\results';
Call doRoot('$(vPath)')

//Only Keep Latest File
FileToLoad:
NoConcatenate
Load max(CheckNumber)
Resident FileName;

inner join 
first 1
Load FilePath 
Resident FileName;

LET vLatestFile = peek('FilePath', 0, 'FileToLoad');

//Load Latest File
FINAL:
Load * 
FROM $(vLatestFile) (qvd);

//cleanup
Drop tables FileName, FileToLoad;
LET file=;
LET subdir=;
LET vPath=;
LET vLatestFile=;
//**********************************************************************************

exit SCRIPT;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 09:47:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582639#M598041</guid>
      <dc:creator>zhadrakas</dc:creator>
      <dc:date>2019-05-21T09:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Load data from the highest folder number</title>
      <link>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582662#M598042</link>
      <description>&lt;P&gt;Thanks so much Tim, I'll try this and let you know.&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 10:36:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-data-from-the-highest-folder-number/m-p/1582662#M598042</guid>
      <dc:creator>davidthorpester</dc:creator>
      <dc:date>2019-05-21T10:36:24Z</dc:date>
    </item>
  </channel>
</rss>

