This topic contains 4 replies, has 3 voices, and was last updated by  rcwoodley 1 month ago.

Issue with os.fs.glob() on Windows when the folder names have square brackets

  • I have an external application which creates files in folders which look like this:
    F:\Output\Preprocessor\[CS00]-[Cardinal]
    When I attempt to use os.fs.glob() to list the files in this folder, I receive this error:

    [CS00]-[Cardinal]/*.*: is recursive

    I’ve tried a number of things in an attempt to escape the square brackets, but to no avail.
    Some things I’ve tried:
    F:\Output\Preprocessor\[CS00]-[Cardinal]\*
    F:/Output/Preprocessor/[CS00]-[Cardinal]/*
    F:/Output/Preprocessor/\[CS00\]-\[Cardinal\]/*
    F:/Output/Preprocessor/%[CS00%]-%[Cardinal%]/*
    F:/Output/Preprocessor/\\[CS00\\]-\\[Cardinal\\]/*

    Any suggestions?

    I’ve also tried these, at Lev’s suggestion:
    "F:/Output/Preprocessor/[CS00]-[Cardinal]\*"
    "F:/Output/Preprocessor/[CS00]-[Cardinal]/"*
    F:/Output/Preprocessor/"[CS00]-[Cardinal]"/*

    The first two resulted in a different error (“not found”), and the third resulted in an error similar to the original: "[CS00]-[Cardinal]"/*: is recursive

    Hello,

    Unfortunately os.fs.glob() does not support handle folder names in the directory path containing square brackets.

    We suggest that you consider choosing a different folder name which does not contain square brackets. Alternatively, you could copy the source folder into a different folder name which does not contain square brackets and then use os.fs.glob() on that folder.

    Regards,
    Sam Bender

    Function os.rename() can help to rename the original folder with a new less ambitious name.
    The standard Lua function glob() should work with non-ambitious paths. This function is accessible in Iguana as os.fs.glob()

    I don’t have control over the folder names. I coded a workaround using a popen of CMD to get the directory listing, parsing it, then iterating over the results calling os.fs.stat myself to get that information. Not as clean. but it works.

You must be logged in to reply to this topic.