Skip to main content
added 131 characters in body
Source Link
george2079
  • 39.1k
  • 1
  • 44
  • 111

a linux version using find to list files and head to take the first n.

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head

Note FileNames[][;;10]] is a good bit faster by my testing, but I don't have a folder with a million files to test it on.

a linux version using find to list files and head to take the first n.

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head

a linux version using find to list files and head to take the first n.

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head

Note FileNames[][;;10]] is a good bit faster by my testing, but I don't have a folder with a million files to test it on.

added 48 characters in body
Source Link
george2079
  • 39.1k
  • 1
  • 44
  • 111

a linux version using find to list files and head to take the first n.

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head

a linux version using find

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head

a linux version using find to list files and head to take the first n.

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head

Source Link
george2079
  • 39.1k
  • 1
  • 44
  • 111

a linux version using find

dir = "/path"
StringSplit[
    RunProcess[
         {"/bin/sh",
          "-c",
          "find "<>dir<>" -maxdepth 1 -type f | head -10"
          },"StandardOutput"]]

note find does not return files in any canonical order, you can sort for example, add | sort in front of | head