-
-
Notifications
You must be signed in to change notification settings - Fork 640
! checking if each match found is either a file or folder appears to … #1850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -350,11 +350,15 @@ | |||||
| -- @param mask | ||||||
| -- The file search pattern. Use "*" to match any part of a file or | ||||||
| -- directory name, "**" to recurse into subdirectories. | ||||||
| -- @param matchType | ||||||
| -- folder will match only folders | ||||||
| -- file will match only files | ||||||
| -- if not set it will match both | ||||||
| -- @return | ||||||
| -- A table containing the matched file or directory names. | ||||||
| --- | ||||||
|
|
||||||
| function os.match(mask) | ||||||
| function os.match(mask, matchType) | ||||||
| mask = path.normalize(mask) | ||||||
| local starpos = mask:find("%*") | ||||||
| local before = path.getdirectory(starpos and mask:sub(1, starpos - 1) or mask) | ||||||
|
|
@@ -370,14 +374,14 @@ | |||||
|
|
||||||
| if recurse then | ||||||
| local submask = mask:sub(1, starpos) .. mask:sub(starpos + 2) | ||||||
| results = os.match(submask) | ||||||
| results = os.match(submask, matchType) | ||||||
|
|
||||||
| local pattern = mask:sub(1, starpos) | ||||||
| local m = os.matchstart(pattern) | ||||||
| while os.matchnext(m) do | ||||||
| if not os.matchisfile(m) then | ||||||
| local matchpath = path.join(before, os.matchname(m), mask:sub(starpos)) | ||||||
| results = table.join(results, os.match(matchpath)) | ||||||
| results = table.join(results, os.match(matchpath, matchType)) | ||||||
| end | ||||||
| end | ||||||
| os.matchdone(m) | ||||||
|
|
@@ -387,10 +391,17 @@ | |||||
| while os.matchnext(m) do | ||||||
| if not (slashpos and os.matchisfile(m)) then | ||||||
| local matchpath = path.join(before, matchpath, os.matchname(m)) | ||||||
|
|
||||||
| if after then | ||||||
| results = table.join(results, os.match(path.join(matchpath, after))) | ||||||
| results = table.join(results, os.match(path.join(matchpath, after), matchType)) | ||||||
| else | ||||||
| table.insert(results, matchpath) | ||||||
| if matchType == "file" and os.matchisfile(m) then | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo? for below too
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not how
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, indeed, misread. |
||||||
| table.insert(results, matchpath) | ||||||
| elseif matchType == "folder" and not os.matchisfile(m) then | ||||||
| table.insert(results, matchpath) | ||||||
| else -- keep previous behaviour | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realised it's this here, it needs to check that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition the comment is not meaningful outside of the pull request. |
||||||
| table.insert(results, matchpath) | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
| end | ||||||
|
|
@@ -412,12 +423,7 @@ | |||||
| --- | ||||||
|
|
||||||
| function os.matchdirs(mask) | ||||||
| local results = os.match(mask) | ||||||
| for i = #results, 1, -1 do | ||||||
| if not os.isdir(results[i]) then | ||||||
| table.remove(results, i) | ||||||
| end | ||||||
| end | ||||||
| local results = os.match(mask, "folder") | ||||||
| return results | ||||||
| end | ||||||
|
|
||||||
|
|
@@ -433,12 +439,7 @@ | |||||
| --- | ||||||
|
|
||||||
| function os.matchfiles(mask) | ||||||
| local results = os.match(mask) | ||||||
| for i = #results, 1, -1 do | ||||||
| if not os.isfile(results[i]) then | ||||||
| table.remove(results, i) | ||||||
| end | ||||||
| end | ||||||
| local results = os.match(mask, "file") | ||||||
| return results | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.