Most of the business implementation - works with File Dump into folders - By Specific Naming Conventions - By Month.
Below script helps to Scan & Reload specific Source files into QlikView.
/////////////////////////////////////////////////////////////////////////////
///$(Loop ForeCast)
/*
Directories that should be scanned for qvw files.
One directory per line. Paths may be local or UNC ( \\server\shareName\Dir\file ) paths.
*/
DirectoriesToScan:
LOAD * INLINE [
Dirspec
C:\QlikView\DataSources\Excel\Forecast
]
;
/////////////////////////////////////////////////////////////////////////////
/*
Subroutine to scan directories and load stats about qvw files.
*/
SUB doDir (dir)
FOR EACH file in filelist('$(dir)' & '\*.xlsx') // Excel 2007 Formats only :: xlsx
Files:
LOAD *
,$(#SCRIPT_START) - FileTime as FileAge
where len(FileName)='21'; // Valid File Name "2014 07 Forecast.xlsx"
LOAD '$(file)' as FilePath
,FileSize('$(file)') as FileSize
,FileTime('$(file)') as FileTime
,subfield('$(file)', '.', -1) as FileExtension
,subfield('$(file)', '\', -1) as FileName
,subfield(subfield('$(file)', '.', 1),'\',-1) as FileBaseName
AUTOGENERATE 1
;
NEXT
FOR EACH subdir in dirlist( '$(dir)' & '\*.xlsx' )
CALL doDir('$(subdir)')
NEXT
END SUB
SUB doRoot (root)
FOR EACH subdir in dirlist( '$(root)' )
CALL doDir('$(subdir)')
NEXT
END SUB
/////////////////////////////////////////////////////////////////////////////
/*
Call the scanning sub for each directory specified in the Configuration tab.
*/
FOR i = 0 to FieldValueCount('Dirspec')
Call doRoot(FieldValue('Dirspec',$(i)));
NEXT i
DROP Table DirectoriesToScan;
/////////////////////////////////////////////////////////////////////////////
FOR i = 0 to FieldValueCount('FilePath')
if(len(FieldValue('FilePath',$(i)))>0) then
Call Forecast_Exctract(FieldValue('FilePath',$(i)));
ENDIF;
NEXT i
/////////////////////////////////////////////////////////////////////////////
///$(QVD_Extractor)
//Remeber to place Sub - before Call functions
sub Forecast_Exctract(vFile_Path)
LET vFileBaseName=subfield(subfield('$(vFile_Path)', '.', 1),'\',-1);
Let vQVDName='C:\QlikView\DataSources\QVD\Forecast\$(vFileBaseName).qvd';
TRACE '$(vFile_Path)';
Forecast_RAW:
LOAD FileBaseName() as Forecast_Source,
*
FROM
'$(vFile_Path)'
//[..\DataSources\Excel\Forecast\2014 07 Forecast.xlsx]
(ooxml, no labels, header is 3 lines, table is [Forecast], filters(
Transpose(),
Replace(3, top, StrCnd(null)),
Transpose()
));
STORE Forecast_RAW into $(vQVDName)(qvd);
DROP Table Forecast_RAW;
end sub
/////////////////////////////////////////////////////////////////////////////
--
Thanks to QlikView Community posts & Robwunderlich - File Monitoring application
//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////////
//////////////////////////////////////// MINI VERSION ////////////////////////////////////////
- Sub ScanFolder(Root)
- for each FileExtension in 'xlsx'
- for each FoundFile in filelist( Root & '\*.' & FileExtension)
- FileList:
- Load Subfield('$(FoundFile)','\',5) as Filename,
- Subfield(Subfield('$(FoundFile)','\',5),'_',2) as Market,
- Subfield(Subfield('$(FoundFile)','\',6),'_',3) as Unit
- Autogenerate(1);
- next FoundFile
- next FileExtension
- for each SubDirectory in dirlist( Root & '\*' )
- call ScanFolder(SubDirectory)
- next SubDirectory
- End Sub
-
- Call ScanFolder('C:\Users\Tamil\Desktop\Test') ;
//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////////