Mathematica Asked on August 27, 2021
I have a directory on my portable hard drive, with around 350000 files under it (there is no subdirectory, only files). I want to get all the file dirs so use
filedirs=FileNames["*",mydir]
However, the code above run for more than 1 hour and still not return a result. Why is FileNames
so slow? What should I do?
I’m using Mathematica 12.0 on my Win10.
The problem is bypassed by running tree dir /f /a >outputtxt
on win10’s cmd window, as suggested by @mikado. The size of outputtxt is only ~20M and it takes only several minites to get result. I still don’t understand why FileNames
will take astonishing time to run.
Under windows system this is the way to get huge number of filenames under a directory:
filenamesFast[dir_]:=
Module[{txtname="temp-alldirs.txt"},
Run["dir ""<>dir<>"" /b >""<>dir<>txtname<>"""];
(dir<>#)&/@StringSplit[Import[dir<>txtname],"n"]
]
Answered by Harry on August 27, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP