HISE Logo Forum
    • Categories
    • Register
    • Login

    Check if (!FILE) do this...

    Scheduled Pinned Locked Moved Solved Scripting
    4 Posts 3 Posters 45 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ChazroxC
      Chazrox
      last edited by Chazrox

      Im trying to just check if a text file exists, read the text....if no file exists, create an empty text file.
      If I was doing this correctly the file should be created upon compiling (f5) correct?

      // Search All Files
      reg rootFolder = FileSystem.getFolder(FileSystem.Desktop);
      reg allFiles = FileSystem.findFiles(rootFolder, "*.wav", true);
      
      const appDataFolder = FileSystem.getFolder(FileSystem.AppData);
      const fileData = appDataFolder.getChildFile("LastUserSelectedFolder.txt");
      
      const LastSelectedLocation = "Test this";
      
      
      Console.print(fileData.loadAsString());
      
      if (fileData)
      {
      	rootFolder = fileData.loadAsString();
      	Console.print("File Is Here: " + rootFolder);
      }
      else
      {
      	Console.print("Nothing Is Here");
      	fileData.writeString("");
      }
      
      Oli UllmannO 1 Reply Last reply Reply Quote 0
      • Oli UllmannO
        Oli Ullmann @Chazrox
        last edited by

        @Chazrox
        I am not at my computer but I think there is a function called .isFile() which you should use in your if-statement.

        ChazroxC 1 Reply Last reply Reply Quote 2
        • iamlampreyI
          iamlamprey
          last edited by iamlamprey

          Yep there's a File.isFile() and File.isDirectory() for folders

          https://docs.hise.audio/scripting/scripting-api/file/index.html

          1 Reply Last reply Reply Quote 2
          • ChazroxC
            Chazrox @Oli Ullmann
            last edited by Chazrox

            @Oli-Ullmann @iamlamprey I promise you guys I was looking for this. hahaha. Thank You 🙏

            That was it...Thank you guys!

            1 Reply Last reply Reply Quote 1
            • ChazroxC Chazrox has marked this topic as solved
            • First post
              Last post

            24

            Online

            2.0k

            Users

            12.8k

            Topics

            111.0k

            Posts