# get-files.ps1
# Gets files using system.io.directory.getfiles()
# Thomas Lee - tfl@psp.co.uk
# Get all files in C:\Foo\test
"Files in C:\Foo\test"
[system.IO.Directory]::GetFiles("C:\foo\test")
""
# Get all files in c:\foo\test\*.txt
"Files in C:\Foo\test\*.txt"
[system.IO.Directory]::GetFiles("C:\foo\test", "*.txt")
""
# Get all files in c:\foo\test\*.* /s
"Files in C:\Foo\test /s"
$s = [system.IO.SearchOption]::AllDirectories
[system.IO.Directory]::GetFiles("C:\foo\test\", "*.*",$s)
This script produces the following output:
PS C:\foo\test> .\get-files.ps1
Files in C:\Foo\test
C:\foo\test\div.xml
C:\foo\test\foo.txt
C:\foo\test\foo1.txt
C:\foo\test\foo1.xls
C:\foo\test\foo1.xlsx
C:\foo\test\foo2.txt
C:\foo\test\shows (Autosaved).xlsx
C:\foo\test\shows.xlsx
C:\foo\test\tfl1.xlsx
C:\foo\test\xlsx1.xlsx
C:\foo\test\xlsx2.xlsx
Files in C:\Foo\test\*.txt
C:\foo\test\foo.txt
C:\foo\test\foo1.txt
C:\foo\test\foo2.txt
Files in C:\Foo\test /s
C:\foo\test\div.xml
C:\foo\test\foo.txt
C:\foo\test\foo1.txt
C:\foo\test\foo1.xls
C:\foo\test\foo1.xlsx
C:\foo\test\foo2.txt
C:\foo\test\shows (Autosaved).xlsx
C:\foo\test\shows.xlsx
C:\foo\test\tfl1.xlsx
C:\foo\test\xlsx1.xlsx
C:\foo\test\xlsx2.xlsx
PS C:\foo\test>