Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It would be very useful to be able to recurse into subdirectories during a file import.
Comments
Comment #1
willvincent CreditAttribution: willvincent commentedThere are a handful of examples around the net on using glob() recursively, but none of them seem to also support patterns.
Attached is a patch that adds this recursive functionality by using the RecursiveIteratorIterator class, and building up a list of all subdirectories within the provided directory. Then the files list is built up by running glob() against each of those, and additionally removing directories from the files list, so that the importer won't try (and fail) to import a directory as a file.
Comment #2
willvincent CreditAttribution: willvincent commentedThis patch is slightly better, previous patch in certain cases would not include everything (including the starting directory)
Comment #3
willvincent CreditAttribution: willvincent commentedAck.. it's one of those days. Removed the extra if that's not needed... this one should be good to go.
Comment #5
willvincent CreditAttribution: willvincent commentedI could have sworn it wasn't a Monday.. Not sure what happened there, this one should apply
Comment #6
willvincent CreditAttribution: willvincent commentedOk.. one last one (hopefully). This is a cleaner method of removing the subdirectories from the file list
Comment #7
queenvictoria CreditAttribution: queenvictoria commentedI've tested the patch in #6 and unfortunately it doesn't work for me with multiple patterns eg: *.jpg|*.png
I'd not discovered this issue before working on it myself (foolishly I'd looked in the file_entity issue queue) so I attach my version as well. It's nearly the same as @willvincent s except it provides a 'recurse' checkbox on the form and uses a regular expression to check for pattern matched files.
Comment #8
willvincent CreditAttribution: willvincent commentedThat's a much nicer solution.
Comment #9
Dave ReidWe just changed the module to use file_scan_directory() now so this needs to be re-rolled.
Comment #10
queenvictoria CreditAttribution: queenvictoria commentedRe-rolled against HEAD
Comment #11
aaron CreditAttribution: aaron commentedThis works fairly well. However, the regex pattern could use an "i" on the end of it, so that it will ignore the case of anything in the pattern. Additionally, I believe that the description on the check box should make it clear that we will iterate through subdirectories.
Comment #12
aaron CreditAttribution: aaron commentedThis patch addresses those concerns.
Comment #13
Dave ReidWasn't the previous code also case-sensitive?
Comment #14
aaron CreditAttribution: aaron commentedyes. should I make a new issue?
Comment #15
30equals CreditAttribution: 30equals as a volunteer commentedHey all,
Since i needed this functionality i decided to pick up this issue and to provide a new patch based on #12.
Tested it locally without a glitch, so testbot, do your thing.
Comment #16
emerham CreditAttribution: emerham as a volunteer commentedSo I just found a use case for this, the patch fails to apply against latest 2.x-dev branch so I rerolled it.
Comment #17
joseph.olstadNice, this is a great feature , I am going to try out this patch myself as I also have a use for this.
Comment #18
joseph.olstadmarking assigned to me, I'll try to test this and review this when I have a few spare cycles. Meanwhile, others please feel free to review and provide feedback.
Comment #19
emerham CreditAttribution: emerham as a volunteer commentedso I used it on two sites so far, and it worked with out issues, I tried to make an interdiff and got errors, but I didn't change any of the code from #1902586-15: Support recursion into subdirectories for file import, just updated the position to what is in 2.x-dev.
Comment #22
joseph.olstadreviewed this, it looks good, and seeing as this recursive import is optional, it should work for everyone.
Comment #23
joseph.olstadtoo bad this didn't make it into 7.x-2.14 , we just tagged and released 2.14 a couple days ago.
however it will make it into 7.x-2.15 whenever that will be.