Directory
- Import can read files from general file directories.
- Import also recognizes formats that are represented as a bundle of related files and organized in a directory structure.
Background & Context
-
- File system directory hierarchy.
- Can contain files and subdirectories.
Import
- When importing from a directory that constitutes a supported multifile Import format, the converter for this format will be used.
- Import["dir"] gives path specifications for all files in a general directory "dir" and its subdirectories.
- Import["dir"] returns a list of pathnames as an expression of the form {"fn1","fn2", …}.
- Import["dir","fn"] imports "\"\!\(\*StyleBox[\"dir\", \"TI\"]\)\!\(\*StyleBox[\"/\", \"TI\"]\)\!\(\*StyleBox[\"fn\", \"TI\"]\)\!\(\*StyleBox[\"\\\"\", \"TI\"]\)".
- Import["dir",elem] imports the specified element from a directory.
- Import["dir",{elem,suba,subb,…}] imports a subelement.
- Import["dir",{{elem1,elem2,…}}] imports multiple elements.
- Because the Wolfram Language can determine whether a path specification refers to a directory, it is normally not necessary to specify "Directory" as a format in the second argument of Import.
- Import["dir","Directory"] or Import["dir",{"Directory",elem,…}] explicitly specifies "Directory" as the Import format.
- See the following reference pages for full general information:
-
Import import from a file CloudImport import from a cloud object ImportString import from a string ImportByteArray import from a byte array
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - The following can be used to select or specify individual files in a directory:
-
"FileNames" list of full pathnames for all files "filename" a single file "filename","format" a single file, taken to be in the specified format "filename","format",elem element elem from the specified file - Import by default uses the "FileNames" element for directories.
- Import["dir","fn"] imports "dir/fn".
- File names can include relative or absolute directory specifications and the abbreviated string patterns supported by StringMatchQ.
- Import["dir","*"] imports an entire directory.
- Import["dir","subdir/*.jpg"] imports all JPEG files from "dir/subdir".
Examples
Basic Examples (1)
Import and count the files included in the user documents directory:
Show the names of some example files included in the Wolfram System:
Import a file from a directory, specifying its name as an Import element: