Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deleting a folder

    Is there a way to remove a folder?
    Actually, in my do file I would like to zip a folder and delete the unzipped one.

    Somthing like below. The second command do not work because Arquivos_dbf is a folder, nor a file. -rmdir- do not work either.
    Code:
    zipfile Arquivos_dbf, saving(Arquivos_dbf, replace)
    erase Arquivos_dbf

  • #2
    See if -help shell- will tell you how to do what you want.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Hi
      i want to delete a folder which not empty
      so i excecute the comand line: shell rmdir "myfolder"
      but it does not work.
      can i have help on this?
      Sorry for my english, i hope it is understandable

      Comment


      • #4
        Code:
        shell rmdir "myfolder" /s
        This deletes the folder and all files and folders in the folder.

        Comment


        • #5
          Many thanks Friedrich Huebler. When I run the code above, the attached blue window shows up. I should then manually enter "y" into the blue window. As I would like to delete folders throughout my code, would it be possible to make Stata delete the folder without showing the blue window or to write a line in the code in which "y" is entered in the blue window?
          Attached Files

          Comment


          • #6
            Below code would help.​​​​But caution should be paid to be sure about what you wanna delete.
            Code:
            shell rd "Folder" /s /q

            Comment


            • #7
              Hi all,
              Following up on a similar problem. I am successfully using the code that Romalpa Akzo shared above to erase files from a dropbox folder on my Windows operating system.
              However, I cannot run the same line of code on my Mac.

              I get the following message:

              rmdir: "Folder": Directory not empty
              rmdir: /s: No such file or directory
              rmdir: /q: No such file or directory


              So somehow Stata (14) recognizes "/s" and "/q" as additional folders, and not commands.
              I already checked that the "Folder" is correct in both computers.

              Any suggestions/help?
              Thanks a lot






              Comment


              • #8
                In Mac OS, try below command:
                Code:
                shell rm -r "The Folder"
                Also consider below line, which moves the folder to the Trash instead:
                Code:
                shell mv -f "The Folder" ~/.Trash

                Comment


                • #9
                  It works! Thank you!

                  Comment


                  • #10
                    Hi. Please ¿how to delete a file, inside a zipped file?
                    I use windows

                    Comment


                    • #11
                      Hi, I used the following command to delete one file on my MAC but deleted all the files on my desktop. Is there anybody who knows how to recover my deleted files? Please help!! Thanks
                      Code:
                      shell rm -r "The Folder"

                      Comment


                      • #12
                        Dont you see your files in the Trash bin?

                        I started using the MacBook Air 2 months ago, and I still have not figured out how to delete files without sending them to Trash first. I.e., it seems that in Mac there is no corresponding to the Shift + Del action on Windows.
                        Originally posted by Joshua Weiss View Post
                        Hi, I used the following command to delete one file on my MAC but deleted all the files on my desktop. Is there anybody who knows how to recover my deleted files? Please help!! Thanks
                        Code:
                        shell rm -r "The Folder"

                        Comment


                        • #13
                          Hello all,
                          This is a related question. I'm trying to empty out all of the files from a folder before populating the same folder with new files (the files are created as part of a foreach loop). Historically, I've done this by deleting the folder using -rmdir- and then recreating the folder by using -mkdir- .

                          Sometime in the past two weeks, the -rmdir- has stopped working. When I run this code:


                          !rmdir "D:\MyDocs\StataUserFiles\Projects\BPAinSTATA\ do_f ile_stages\Stage5\DTAfiles" /s /q


                          STATA produces the following comments:

                          Remove-Item : A positional parameter cannot be found that accepts argument '/s'.
                          At line:1 char:1
                          + rmdir D:\MyDocs\StataUserFiles\Projects\BPAinSTATA\do_fi le_stages\Sta ...
                          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
                          + CategoryInfo : InvalidArgument: ( [Remove-Item], ParameterBindingException
                          + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.C ommands.RemoveItemCommand




                          I am using version 18, but have also gone back and set the version to 17.0 and the same comments appear.
                          I've checked the directory path several times, including copying and pasting the directory path to avoid typos. No help.
                          I cannot find anything on "Remove-Item."

                          I presume I'm missing something obvious.
                          Any ideas?
                          Thank you!

                          Comment


                          • #14
                            I think the title of this thread is not clear enough for my issue, so I am creating a new thread for this.
                            The new location of the post is here: https://www.statalist.org/forums/for...-s#post1730033
                            Last edited by James Voss; 12 Oct 2023, 14:05.

                            Comment

                            Working...
                            X