Automation Return Value

AlbertvhAlbertvh Member Posts: 516
Hi

Could anybody tell me what the return part of the statement should be


[IFOLDER CreateFolder :=] FileSystem.CreateFolder(BSTR Path)


FileSystem is automation 'Microsoft Scripting Runtime'.FileSystemObject

Thanks

Albert

Answers

  • garakgarak Member Posts: 3,263
    you can set the Return Value to the IFOLDER Object. And work with the properties / functions of this.
    WSHFSO -->  'Windows Script Host Object Model'.FileSystemObject	
    WSHFolder -->  'Windows Script Host Object Model'.Folder
    
    WSHFolder := FileSystem.CreateFolder('C:\MyFolder);
    //example
    message('The Foldername is %1',WSHFolder.Name);
    

    Regards
    Do you make it right, it works too!
  • AlbertvhAlbertvh Member Posts: 516
    Hi Garak,
    Thanks for your response.I have this scenario.
    I have a table with a directory field eg \\net\document\template
    when I use the code as you have suggested I get this error
    This message is for C/AL programmers.
    An exception was raised in method CreateFolder. The OLE control or Automation serverhas returned error (HRESULT)
    -2147352567
    Thecomponent did not provide the exception description

    Thanks

    Albert
  • garakgarak Member Posts: 3,263
    Hi Albert,

    that was only an example based on your question.
    Other question. What do you want (whats the reason) to do with the UNCPath and the directory?
    You whish to open the folder? Access all files in the folder or what?

    Regards
    Do you make it right, it works too!
  • AlbertvhAlbertvh Member Posts: 516
    Hi Garak,
    Sorry was not in yesterday.
    I check if the directory exists and if not I try and create it, however it will not create a folder \\net\Document\Template so I was trying to avoid the error. I can't use an If statement either.
    I do know that I can create the folders one by one. ie \\net\Document and then \\net\Document\Template

    I think I will change the logic and give the user an error telling them that the directory doesn't exist.


    Albert
  • garakgarak Member Posts: 3,263
    if isclear(WSHFSO) then
      create(WSHFSO);
    
    if not WSHFSO.FolderExists('C:\temp\Test') then begin
      WSHFolder := WSHFSO.CreateFolder('C:\temp\Test');
    end;
    
    WSHFolder := WSHFSO.GetFolder('C:\temp\Test');
    
    Do you make it right, it works too!
  • AlbertvhAlbertvh Member Posts: 516
    Hi Garak,

    I did try to do that but still the error popped up.

    Albert
  • garakgarak Member Posts: 3,263
    do you have access to create a folder in the directory?
    Do you make it right, it works too!
  • AlbertvhAlbertvh Member Posts: 516
    Hi Garak,

    What I want to do is check if the directory exists, I have permission to create folders, however the base folder does not exist in this case Document. So if I try and create \\net\Document\Template I get the error, it is trying to create the folder \\net\Document\Template in one step instead of two.


    Albert
  • garakgarak Member Posts: 3,263
    CreateFolder can only create one folder and not a foldertree.
    So you must check if the base exist and then create the other folders.
    If the base doesn't exist, create it and then create the other folders.

    \\net\ <-- hope it's the UNC Path and not a drive letter ;-)
    Do you make it right, it works too!
  • AlbertvhAlbertvh Member Posts: 516
    Hi Garak,

    I know that but I just wanted to check if there was a return code but now I know there isn't I will change my code.
    Thanks for your help. I'll mark it as solved.

    Albert
Sign In or Register to comment.