Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
If I have a directory/folder with list of files like -
QVW1, QVW2, QVW3...... QVWN.
Using a For Loop, I want to Pick ANY ONE or a Small Sized File name into a variable.
Suggestion please!
I'm not sure what you're trying to achieve, but if you just want one file, you can use the standard file-reading loop but end it after the first successful read. If you'd prefer to randomize it, generate a random number into a variable and then skip reading unless the iteration number matches that number.
Hi orsh_
Thanks for suggestion.
Basically, I am trying to do a Back Up of a Single File from each category from a DESTINATION Path/Folder.
SOURCE Path has files - QVW1, QVW2, QVW3...... QVWN.
DESTINATION Path has files - QVW1, QVW2, QVW3...... QVWN.
Before I overwrite the files in the Destination Path, want to do a Back Up of the files from each category(that FOR Loop will pick any one from the directory). Then will COPY the files from SOURCE to DESTINATION.
Hope his is clear to you.
Hi Dicky,
Please check the below scripts for loading multiple files/single files/ single sheet/ multiple sheets/ from multiple folders using for each
1) multiple files from multiple folders:
FOR Each vdata in DirList('C:\Users\Admin\Desktop\Workspace\Qlikview\Practice\For Loops\For Each Loop\For multiple Folders - multiple files\*')
TRACE $(vdata);
FOR Each vdatafiles in FileList('$(vdata)\*');
TRACE $(vdatafiles);
Fact: LOAD *,
FileBaseName() as Filebasename,
FileDir() as Filedir,
FileName() as Filename,
FilePath() as Filepath
FROM
[$(vdatafiles)]
(ooxml, embedded labels, table is Sheet1);
NEXT vdatafiles;
NEXT vdata;
2) Single from multiple folders
FOR Each vdata in DirList('C:\Users\Admin\Desktop\Workspace\Qlikview\Practice\For Loops\For Each Loop\For multiple Folders- single file\*')
LOAD *
FROM
[$(vdata)\*.xlsx]
(ooxml, embedded labels, table is Sheet1);
TRACE $(vdata);
NEXT vdata;
3) Single file from single folder
Set vpath= C:\Users\Admin\Desktop\Workspace\Qlikview\Practice\For Loops\For Each Loop;
FOR Each vdata in 1,2,3
$(vdata):
LOAD *,
'$(vdata)' as Tableflag
FROM
[$(vpath)\Sample Database $(vdata).xlsx]
(ooxml, embedded labels, table is Sheet1);
TRACE vdata;
NEXT vdata;
Thanks for this. We are extensively using this and aware of this anyways.
But the requirement is slightly different. Need to Pick/Select ANY ONE .qvw from each Category and COPY them .
Let me explain more.
For example, In a folder we have below 9 .qvws -
QVW1
QVW2
QVW3
QVW4
File A
File B
File C
Application_1
Analyzer QVW
I need to Copy a ANY ONE from QVW1, QVW2, QVW3, QVW4 - lets say QVW3.
I need to Copy a ANY ONE from File A, File B, File C - lets say File A
I need to Copy a ANY ONE from Application_1, i.e. Application_1
I need to Copy a ANY ONE from Analyzer QVW i.e. Analyzer QVW
In total, I need to Pick/Select and COPY to different directory.
Any further suggestions here?
Try Using Execute in the script
EXECUTE cmd.exe /C copy "C:\Desktop\POC\qvdtest.qvw" "C:\Desktop\POC\Copy Files"
source folder is: C:\Desktop\POC\
File to be copied: qvdtest.qvw
Destination folder is: C:\Desktop\POC\Copy Files
Sorry, you didn't get this still.
Copying through EXECUTE command is fine. Before that ned to select/pick a single file.
I need to Copy a ANY ONE from QVW1, QVW2, QVW3, QVW4 - lets say QVW3.
I need to Copy a ANY ONE from File A, File B, File C - lets say File A
I need to Copy a ANY ONE from Application_1, i.e. Application_1
I need to Copy a ANY ONE from Analyzer QVW i.e. Analyzer QVW
In total, I need to Pick/Select 4 .qvws