Read the property of a file

fabou3377fabou3377 Member Posts: 11
Hi,

I try to read a folder content with this code :

Name DataType Subtype Length
fso Automation 'Windows Script Host Object Model'.FileSystemObject
folder Automation 'Windows Script Host Object Model'.Folder
files Automation 'Windows Script Host Object Model'.Files
file Automation 'Windows Script Host Object Model'.File
folder:=fso.GetFolder('\\lamsrv01\fileExchange\production\navToLalima\item');
files:=folder.Files;
MESSAGE(FORMAT(files.Count));

file:=files.Item(1);
MESSAGE(file.Name);


The first message work, I have the count but with the second I receive an error.

How I can get the file?? I have already try with the Microsoft Scripting Runtime, i get the same error.
I can't do with the table file of Navision, because the update of this table is n't quickly...

Thanks for your help

Comments

  • krikikriki Member, Moderator Posts: 9,110
    Check this topic : http://www.mibuso.com/forum/viewtopic.php?t=7855.
    Maybe it gets you on the way.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • fabou3377fabou3377 Member Posts: 11
    Thanks! It's work fine...


    My Function:


    getFiles(VAR _files : Automation "'Microsoft Scripting Runtime'.Dictionary";_directory : Text[250])

    Name DataType Subtype Length
    fso Automation 'Windows Script Host Object Model'.FileSystemObject
    folder Automation 'Windows Script Host Object Model'.Folder
    files Automation 'Windows Script Host Object Model'.Files
    scr Automation 'Microsoft Script Control 1.0'.ScriptControl
    txtCr Text 30
    txtCode Text 250
    i Integer
    IF ISCLEAR(fso) THEN
      CREATE(fso);
    
    IF ISCLEAR(_files) THEN
      CREATE(_files);
    
    folder:=fso.GetFolder(_directory);
    files:=folder.Files;
    
    CREATE(scr);
    scr.Language := 'VBScript';
    //variable files is visible in script as FilesByName
    scr.AddObject('FilesByName', files);
    //variable _files is visible in script as FilesById
    scr.AddObject('FilesById', _files);
    
    //copy objects using VBScript
    txtCr := ' '; txtCr[1] := 13;
    txtCode :=
    'dim f1' + txtCr +
    'For Each f1 in filesByName' + txtCr +
    ' filesById.Add (filesById.Count+1), f1' + txtCr +
    'Next' + txtCr;
    scr.ExecuteStatement(txtCode);
    
    CLEAR(fso);
    CLEAR(scr);
    
    

    Call the function:

    file Automation 'Windows Script Host Object Model'.File
    filesCol Automation 'Microsoft Scripting Runtime'.Dictionary
    i Integer
    getFiles(filesCol,'\\lamsrv01\fileExchange\production\navToLalima\item\');
    
    FOR  i:=1 TO filesCol.Count() DO BEGIN
      file := filesCol.Item(i);
      MESSAGE(file.Name);
    END;
    
Sign In or Register to comment.