Folder exist

jensthomsenjensthomsen Member Posts: 173
Hi
I need to check if a certain folder exist - that is, does C:\temp\MyFolder\ exist. What would be the easiest way of doing this?
Jens

Comments

  • ara3nara3n Member Posts: 9,256
    Directory is record type and subtype is File
    clear(Directory);
    Directory.setrange(Path,'C:\temp\');
    FolderExists := Directory.findfirst;
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • jensthomsenjensthomsen Member Posts: 173
    Hi ara3n
    Thats not quite good enough. If the folder doesn't exist, you will still get an error...
  • rvduurenrvduuren Member Posts: 92
    ara3n wrote:
    Directory is record type and subtype is File
    clear(Directory);
    Directory.setrange(Path,'C:\temp\');
    FolderExists := Directory.findfirst;
    

    Hello,
    I did not get an error using SETFILTER..
    Directory.SETFILTER(Path,'C:\'); // Works better than CLEAR :)
    IF Directory.findfirst THEN; // Works better than CLEAR :)
    Directory.SETFILTER(Path,'C:\temp\');
    Directory.SETRANGE("Is a file",false);
    MESSAGE('%1',Directory.findfirst);
    
    Hope this helpes you..
    Met vriendelijke groet, best regards,

    Rvduuren
  • jensthomsenjensthomsen Member Posts: 173
    Hi rvduuren
    As far as I understand, your check is if there exists subfolders in the folder c:\temp...? I want to check if c:\temp\ exists...
  • rvduurenrvduuren Member Posts: 92
    Hi rvduuren
    As far as I understand, your check is if there exists subfolders in the folder c:\temp...? I want to check if c:\temp\ exists...

    Hello Jens,

    I'm not checking any subfolders with above code, just if c:\temp exists. But you can also use FileSystemObject:
    Globals:Folder - Automation - 'Windows Script Host Object Model'.FileSystemObject
    
    create(Folder);
    message('%1',Folder.FolderExists('c:\temp'));
    clear(Folder);
    
    Met vriendelijke groet, best regards,

    Rvduuren
  • ajhvdbajhvdb Member Posts: 672
    if EXISTS(C:\nul') then ... should work too.
  • ara3nara3n Member Posts: 9,256
    ajhvdb wrote:
    if EXISTS(C:\nul') then ... should work too.

    This won't work. Exists only is used for files not folder.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ajhvdbajhvdb Member Posts: 672
    :shock: Did you try it? or did you test it? :)
  • ara3nara3n Member Posts: 9,256
    What is the difference?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • DenSterDenSter Member Posts: 8,305
    I tried it, and I also tested it :mrgreen:
    Doesn't work, it always returns FALSE
  • ajhvdbajhvdb Member Posts: 672
    I'm using it in production and it does work...it was working in the days of MSDOS but maybe in other countries not.

    create a button and put this in the push event:
    message('%1', EXISTS('C:\WINDOWS\nul'));
    message('%1', EXISTS('D:\nul'));
    message('%1', EXISTS('X:\WINDOWS\nul'));
    message('%1', EXISTS('D:\DATA\nul'));
    

    Run it and if you have a D: drive and D:\DATA, it answers:
    Yes
    Yes
    No
    Yes
  • DenSterDenSter Member Posts: 8,305
    edited 2007-12-10
    OBJECT Form 60000 Exist
    {
      OBJECT-PROPERTIES
      {
        Date=12/10/07;
        Time=[ 1:30:23 PM];
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=2640;
        Height=990;
      }
      CONTROLS
      {
        { 1000000000;CommandButton;220;220;2200;550 ;CaptionML=ENU=Click;
                                                     OnPush=BEGIN
                                                              MESSAGE('%1',EXISTS('C:\Windows\nul'));
                                                              MESSAGE('%1',EXISTS('C:\Dummy\nul'));
                                                            END;
                                                             }
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    The part that makes this work is "nul", with just one 'l', at the end of the folder path :mrgreen:
    <edit>modified post with updated information</edit>
  • DenSterDenSter Member Posts: 8,305
  • ara3nara3n Member Posts: 9,256
    that is some undocumented feature, I hope will be supported in 6.0?

    Since the exists will run in service tier .net dll.

    Learning something new every day.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • NaviDevNaviDev Member Posts: 365
    You can use the automation 'Microsoft Scripting Runtime'.FileSystemObject. Use the function FolderExists. Just pass the path and it will return a boolean value weather the certain folder exists or not.
    Navision noob....
Sign In or Register to comment.