Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a scenario as below:
This is the folder structure we have for the log files under Distribution Service which will be created for each task running in QMC.
Folder1
- Folder2
- Folder3
- File.txt
Folder1 - will be the constant path
Folder2 - have to loop through all folder2 in folder1 (achieved). This folder will be created for each day with the date as 20120201 like this.
Folder3 - for each task a folder will be created with time (010523-Reload_XXX)
File.txt - Is the log file.
So for a same date and for same task there might be more than 1 folder for different time.
So my requirement is to choose the latest folder or the last created folder as it will have the full log file among those.
Currently I looping through folders and fetching the data from the log file. While fetching I need to have a condition like for a particular date and for a particular task is there more than 1 file if so choose the last created folder and its log file.
Thanks in Advance
~ Leni
You can try something like this.
Load the fileName and Created Time from all the folders. Then subset the table by the max of Created time by File name.
So your Script should look like below.
sub DoDir (Root)
for each Ext in 'log'
for each File in filelist (Root&' \*.' &Ext)
DATA:
Load '$(File)' as Name, FileTime( '$(File)' ) as FileTime
autogenerate 1;
next File
next Ext
for each Dir in dirlist (Root&' \*' )
call DoDir (Dir)
next Dir
end sub
call DoDir ('C:')
DATA1:
Load Max(FileTime) as Created_Time,Name as FileName Resident DATA Group by Name;
Regards,
Kaushik Solanki
I think you need to see this thread:
http://community.qlik.com/message/3879#3879
This is the code used to get files name and time, after that you only need to get the first two from the resident table.
for each File in filelist ('C:\myFolder\*.*')
Folder:
Load '$(File)' as Name,
FileTime( '$(File)' ) as FileTime
autogenerate 1;
next File
Regards
Thanks for your answer.
I am fetching the data from log file (document.txt) which will be @ ....\distribution service\1\log\all folders(created for each date [20120101])\time-Reload_XXX\document.log file
so in this, inside 20120101 folder there is a possibility for me to have more than one folder for Reload_XXX but the time will be different which is prefixed on Reload_XXX.
So while I am looping through the subfolders ...\20120101\Time-Reload_XXX\ I need to have a condition like Reload_XXX is from same folder path or different path. From same path, then I have to l choose the latest folder and its document.txt log file alone.
So how to give the condition??
Hi Kaushik,
Is there any solution to achieve my requirement??
If you could provide some logic, it would be very helpful for me.
Thanks,
Leni