omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    File manager rename and copy functions

    Pythonista
    4
    9
    7424
    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.
    • lsloan
      lsloan last edited by

      Please add features to the file manager to allow copying an existing file into a new one and renaming files.

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by dgelessus

        Renaming files is already possible. Open the file in the editor, tap its title and then the little rename icon. For folders, go into the folder, switch to "Edit" mode, and then you have a rename icon next to the "Done" button.

        For copying files I use a short script like this as an editor action:

        import console
        import editor
        import os
        import shutil
        
        DOCUMENTS = os.path.expanduser("~/Documents")
        
        old_name = editor.get_path()
        new_name = os.path.join(DOCUMENTS, console.input_alert("Duplicate File", "Enter new name", os.path.relpath(old_name, DOCUMENTS)))
        
        if os.path.exists(new_name):
            console.hud_alert("Destination already exists", "error")
        else:
            shutil.copy(old_name, new_name)
            
            ##editor.open_file(os.path.relpath(new_name, DOCUMENTS)) # For old Pythonistas
            editor.open_file(new_name)
        

        Of course this only works one file at a time. For copying multiple files stash is currently the best solution.

        lsloan 1 Reply Last reply Reply Quote 0
        • brumm
          brumm last edited by

          PhoneManager !?

          lsloan 1 Reply Last reply Reply Quote 0
          • lsloan
            lsloan @brumm last edited by

            @brumm Really!? I will check that out?!

            P.S. You might like interrobang: ‽

            ;)

            1 Reply Last reply Reply Quote 0
            • brumm
              brumm last edited by

              Yes, I love it (now that I know it). 😀

              1 Reply Last reply Reply Quote 0
              • lsloan
                lsloan @dgelessus last edited by

                Thanks for the suggestions, @dgelessus.

                The rename feature in the editor isn't enough. In my case, it's not even possible for one file.

                As an experiment, I renamed a .pyui file to .json. I changed some coordinates from "{{x,y},{w,h}}" strings to [[x,y],[w,h]] structures. It worked in the app that used it, but when I renamed the file back to .pyui, all attempts to open it cause Pythonista itself to crash.

                I know I can rename or copy files with function calls from the console or a program. However, the file manager should have this feature, too. It feels incomplete without them.

                1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  @lsloan The UI editor doesn't handle malformed files very well. If you're in a crash loop, you can launch Pythonista by entering pythonista:// in Safari's address bar. This will skip restoring the previously-open files.

                  lsloan 1 Reply Last reply Reply Quote 1
                  • dgelessus
                    dgelessus last edited by

                    Of course that crashes Pythonista. You're changing the internal structure of a file that is not meant to be edited by hand. Okay, Pythonista should probably display an error instead of crashing entirely, but this is not exactly the normal use case of pyui files. ;)

                    The current state is also much better than what it was like in version 1.5. There the editor would refuse to open files with an unknown extension, even if they were text files, and when renaming it would automatically set the extension to .py if you used something other than .py or .txt.

                    1 Reply Last reply Reply Quote 0
                    • lsloan
                      lsloan @omz last edited by

                      @omz Thanks, I'd forgotten about that trick.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors