Announcement

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

  • Local dir saves two file names instead of one

    Dear Stata users,

    I want to local excel files in one of my folders to make a loop over them

    For simplicity, let's assume I have two files in a folder "my_dir/2020/file1.xlsx" and "my_dir/2020/file2.xlsx"

    I start from the following code to local all needed files in the directory:

    local files : dir "my_dir/2020" files "*.xlsx"

    If I check this local by using display "`files'"

    I get four saved files "_.file1.xlsx", "file1.xlsx", "_.file2.xlsx", "file2.xlsx" ""

    And these two files that I get do not exist in reality: "_.file1.xlsx", "_.file2.xlsx" and I do not understand why they appear in local

    However, if I use same code to local dta files everything works correctly, so my problem is with xls and xlsx files

    I assume that the problem can be because I recently switched from mac to windows and do not understand some peculiarities of writing code on windows. However, I tried different variants of slashes ("/", "", or all "/" except for last one) and it didn't help

    I need some help with understanding why these strange additional files are created.

    Best regards,
    Kira
    Last edited by Kira Silvestrovich; 16 Feb 2023, 15:15.

  • #2
    The problem is that when macOS writes files to a filesystem formatted in one of Windows native formats, it creates these _. files to store macOS-specific information about the file with the same name, so that if the file is read back into macOS that information won't be lost. So those files were created when your Mac wrote the to whatever you used to transfer them to your Windows system. Or perhaps you directory is on a network drive with a Windows native format, and macOS was quietly creating the ._ files it needed and keeping you from seeing them on your Mac.

    Since in their current location they're not going to be used by you on a Mac, you do not need the info in these files and you can delete them wherever you find them. And if you give one to someone on a Mac, it will be OK - the information that's lost is stuff like any tag you've attached to the file - the contents of the file itself are identical on both systems, and that's all apps like Stata care about.
    Last edited by William Lisowski; 16 Feb 2023, 16:59.

    Comment


    • #3
      In addition to @William Lisowski's helpful answer, let's flag -- especially with reference to the last sentence of #1 -- that there is no sense whatsoever in which the creation of a local macro creates extra files, here or anywhere else. The local macro is defined with information from the operating system and here documents the existence of files you dd not know about.

      Comment


      • #4
        Looking more closely at post #1, let me add - as someone who has not used Windows in almost 10 years - that I did not understand that when viewed from Windows File Explorer they are hidden from view, which certainly makes it appear that they don't exist. I'm guessing your .dta files do not have this problem because created them on the Windows system.

        For Windows 11 and Windows 10 the following Microsoft link explains how to get the unhidden in File Explorer.

        https://support.microsoft.com/en-us/...ion=Windows_11

        Also, with your example your spreadsheet files start with the same letter(s), so you could try
        Code:
        local files : dir "my_dir/2020" files "files*.xlsx"
        which ought to ignore the hidden files.

        Comment

        Working...
        X