Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I need to load the existing file names from a range of directories for which the path is coming from a table. I tried:
[FileDirs:
LOAD FileDir RESIDENT FileDirTable;
For i = 0 to NoOfRows( 'FileDirs' )
LET ActualDir = peek( 'FileDir', $(i), 'FileDirs );
Directory $(ActualDir);
LET FileList = '*.*';
FOR EACH varFile i nFileList (strFileList)
Files:
LOAD
$(ActualDir) as FileDir,
$(varFile) as PathFileName
AUTOGENERATE 1;
NEXT varFile
NEXT i
It works fine unless the FileDir exists as a directory but if not it reads the files from the previous directory a second time. Any change to get checked if the directory exists?
Thanks for any help
Christian
Would give it a try with checking the size of the File, which would deliver 0, in case that there is no file:
FOR EACH varFile i nFileList (strFileList)
IF FILESIZE($(varFile)) > 0 THEN
Files:
LOAD ....
END IF
NEXT varFile
HTH
Peter
Thanks Peter for the quick response.
However, the problem is not that there is no file, the problem is, that the complete directory does not exist. QV than keeps the last directory that worked and simply takes the files in that directory.
To give example data:
Lets say Table.FileDir has two values : c:\temp\Dir1 and c:\temp\Dir2
in c:\temp\dir1 exists with two files file1.xls and file2.xls
c:\temp\dir2 does not exist
First Directory statement loads the two filenames, second Directory statement loads this two filenames again.
Unfortunately the Directory statement do not return an error status message when teh directory does not exist.
To be honest I tried to find a solution with QV - not using VB because I am lacking VB skills...
Regards
Christian
I'm not following where you are setting strFileList. But I think you want to delete the Directory statement and do something like:
FOR EACH varFile i nFileList ('$(ActualDir)\$(strFileList)')
-Rob
Dear Rob,
sorry it seems to be a bit complicated to explain. I will try again in a bit more in detail:
I have a comment table:
Comments:
LOAD * INLINE [
COMMENT_ID, COMMENT
1, comment_one
2, comment_two
3, comment_three
]
In reality the user can store to each comment files. the files are stored in a way, the they are placed in a sub-dir with the sub-dir-name COMMENT_ID. I want to have a field with the filenames of the comment stored to open the documents from the application
In this example I may have a comment file structure with documents
c:\application_comments\1\comment_one.xls
c:\application_comments\1\comment_one.pdf
c:\application_comments\3\comment_three.xls
This are two files for comment 1, no file for comment 2 and one file for comment 3.
What I do now:
For i = 0 to NoOfRows( 'Comments' ) - 1 // for each COMMENT_ID
LET ActualDir = peek( 'COMMENT_ID', $(i), 'Comments' );
Directory c:\application_comments\$(ActualDir); // set path for files
LET FileList = '*.*';
FOR EACH varFile in FileList (strFileList)
Files:
LOAD
$(ActualDir) as FileDir,
$(varFile) as PathFileName
AUTOGENERATE 1;
NEXT varFile
NEXT i
As you see for i = 1 the directory c:\application_comments\2 does not exist because there is no comment file for comment 2
The output of this loop is:
Files
c:\application_comments\1\comment_one.xls
c:\application_comments\1\comment_one.pdf
c:\application_comments\1\comment_one.xls
c:\application_comments\1\comment_one.pdf
c:\application_comments\3\comment_three.xls
Loading directory c:\application_comments\1\ twice.
What I am looking for is a way to get the information, that directory c.\application_comments\2 does not exist.
Christian