Skip to main content
added 333 characters in body
Source Link
bill s
  • 69.7k
  • 4
  • 103
  • 198

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

This reads the names of all files (in the specified path directory) that have the extension ".txt" and places the file names in a list called fileNames. It then reads all the files in this list. They can be be named anything at all, as long as they have the specified extension.

Of course you could use a different extension than .txt, you could specify the directory namepath in the code (instead of using the GUI) and, you can use Get instead of Import, and Do instead of Table. You could also filter out files you don't want before importing, if this is desirable.

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could specify the directory name in the code (instead of using the GUI) and you can use Get instead of Import, and Do instead of Table. You could also filter out files you don't want before importing, if this is desirable.

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

This reads the names of all files (in the specified path directory) that have the extension ".txt" and places the file names in a list called fileNames. It then reads all the files in this list. They can be be named anything at all, as long as they have the specified extension.

Of course you could use a different extension than .txt, you could specify the directory path in the code (instead of using the GUI), you can use Get instead of Import, and Do instead of Table. You could also filter out files you don't want before importing, if this is desirable.

added 117 characters in body
Source Link
bill s
  • 69.7k
  • 4
  • 103
  • 198

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could specify the directory name in the code (instadinstead of using the GUI) and you can use Get instead of Import, and Do instead of Table. You could also filter out files you don't want before importing, if this is desirable.

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could specify the directory name in the code (instad of using the GUI) and you can use Get instead of Import.

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could specify the directory name in the code (instead of using the GUI) and you can use Get instead of Import, and Do instead of Table. You could also filter out files you don't want before importing, if this is desirable.

added 77 characters in body
Source Link
bill s
  • 69.7k
  • 4
  • 103
  • 198

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could specify the directory name in the code (instad of using the GUI) and you can use Get instead of Import.

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could use Get instead of Import.

One way to go about this is read in the file names - this way you don't have to explicitly check to see if they exist.

 path = SystemDialogInput["Directory", NotebookDirectory[]];
 fileNames = FileNames["*.txt", path];
 allFiles = Table[Import[fileNames[[num]]], {num, 1, Length[fileNames]}];

Of course you could specify the directory name in the code (instad of using the GUI) and you can use Get instead of Import.

Source Link
bill s
  • 69.7k
  • 4
  • 103
  • 198
Loading