• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

File exists check

Scheduled Pinned Locked Moved
Firmware wishlist
5
13
636
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.
  • undefined
    dc42 administrators
    last edited by 5 Dec 2020, 21:30

    I've added this to the work list.

    Duet WiFi hardware designer and firmware engineer
    Please do not ask me for Duet support via PM or email, use the forum
    http://www.escher3d.com, https://miscsolutions.wordpress.com

    undefined undefined 2 Replies Last reply 7 Jun 2021, 19:37 Reply Quote 0
    • undefined
      DonStauffer @dc42
      last edited by 7 Jun 2021, 19:37

      @dc42 Has it been decided what firmware version this will be in? Thanks!

      undefined 1 Reply Last reply 7 Jun 2021, 21:48 Reply Quote 0
      • undefined
        Phaedrux Moderator @DonStauffer
        last edited by 7 Jun 2021, 21:48

        @donstauffer I believe it will be in 3.3

        exists name -> bool Yields true if 'name' is a valid variable or object model element name and is not null (available in RRF 3.3beta3 and later). Especially useful for testing whether a particular parameter has been provided when a file macro was called.

        https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Functions

        Z-Bot CoreXY Build | Thingiverse Profile

        undefined 1 Reply Last reply 7 Jun 2021, 22:11 Reply Quote 0
        • undefined
          DonStauffer @Phaedrux
          last edited by 7 Jun 2021, 22:11

          @phaedrux This is about files, not variables.

          undefined 1 Reply Last reply 7 Jun 2021, 22:11 Reply Quote 0
          • undefined
            Phaedrux Moderator @DonStauffer
            last edited by 7 Jun 2021, 22:11

            @donstauffer ah, my mistake.

            Z-Bot CoreXY Build | Thingiverse Profile

            undefined 1 Reply Last reply 7 Jun 2021, 22:15 Reply Quote 0
            • undefined
              DonStauffer @Phaedrux
              last edited by DonStauffer 6 Jul 2021, 22:17 7 Jun 2021, 22:15

              @phaedrux I found a very awkward workaround: M471 is the only code I know of which returns a result that tells you something about the existence of a file. Unfortunately, it does that when potentially deleting the file in question. I didn't want that, so I had to set up a system of dummy "semaphor" files created in parallel with the file I was interested in, which fortunately my macros created, so it could keep the semaphors consistent with the actual file status.

              But all that turned what would have been about a half page of code with a file exists capability into about 2 pages.

              1 Reply Last reply Reply Quote 1
              • undefined
                Phaedrux Moderator
                last edited by 7 Jun 2021, 22:39

                @dc42 would have to comment on whether it's been implemented yet for sure.

                Z-Bot CoreXY Build | Thingiverse Profile

                1 Reply Last reply Reply Quote 0
                • undefined
                  OwenD
                  last edited by 8 Jun 2021, 04:31

                  As a work around you can use M38.

                  M38: Compute SHA1 hash of target file

                  Example:

                  M38 gcodes/myfile.g
                  

                  Used to compute a hash of a file on the SD card and returns a hexadecimal string which is the SHA1 of the file. If the file cannot be found, then the string "Cannot find file" is returned instead.

                  undefined 1 Reply Last reply 2 Jul 2021, 14:56 Reply Quote 1
                  • undefined
                    DonStauffer @OwenD
                    last edited by DonStauffer 7 Feb 2021, 14:58 2 Jul 2021, 14:56

                    @owend How can my GCode use the string returned by M38? For example, how could I use it in a conditional? How do I suppress the spurious error message which displays in the console and as a pop-up in the web interface?

                    undefined 1 Reply Last reply 2 Jul 2021, 21:22 Reply Quote 0
                    • undefined
                      OwenD @DonStauffer
                      last edited by 2 Jul 2021, 21:22

                      @donstauffer
                      You can't suppress the error message.
                      You don't exactly use the string. It's more a case of checking the result.
                      A result code of zero means I it's found and RRF was able to create a hash.
                      A result of 2 means the files wasn't found.
                      A result of 1 means the call to M38 returned a warning but I'm not sure of what conditions might return that result.

                      It's not very elegant but it's the best we have for now.

                      M38 "gcodes/my file.g"
                      if result = 2
                            echo "file not found"
                      elif result  = 1
                          echo "M38 call failed"
                      elif result = 0
                          echo "file exists"
                      
                      1 Reply Last reply Reply Quote 0
                      • undefined
                        mher @dc42
                        last edited by 20 Nov 2022, 17:48

                        @dc42 Is there any news about this. It would be really nice to check if a file exists or not.

                        undefined 1 Reply Last reply 20 Nov 2022, 18:05 Reply Quote 0
                        • undefined
                          dc42 administrators @mher
                          last edited by 20 Nov 2022, 18:05

                          @mher a new function fileexists(name) is already implemented in the RRF 3.5 source code.

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          1 Reply Last reply Reply Quote 2
                          • First post
                            Last post
                          Unless otherwise noted, all forum content is licensed under CC-BY-SA