-
Notifications
You must be signed in to change notification settings - Fork 22
File Lists
You can use file lists to find all the files whose path matches a particular pattern. This is useful for copying certain files from one directory to another.
You can create a file list by crating an instance of the FileList class and calling the Include method:
fl = FileList() fl.Include("some/directory/*.{dll,exe}")
This creates a FileList containing all of the .exe and .dll files from some/directory.
Each FileList takes a base directory in its constructor. If a base directory is ommitted, the current working directory is assumed.
Once created, you can iterate over the FileList to get access to FileSystemInfo objects:
fl = FileList("some/directory") fl.Include("*.{dll,exe}") for file in fl: print file.Name
There is a CopyToDirectory method available on the custom FileSystemInfo instance that allows you to easily copy the files to another directory:
fl = FileList("some/directory") fl.Include("*.{dll,exe}") for file in fl: file.CopyToDirectory("directoryToPackage")
You can also use the With Syntax keyword in conjunction with the ForEach extension method to make this more concise:
with FileList(): .Include("some/directory/*.{dll,exe}") .ForEach def(file): file.CopyToDirectory("directoryToPackage")
You can also exclude files matching particular patterns:
with FileList("some/directory"): .Include("*.{dll,exe}") .Exclude("Phantom.exe") .ForEach def(file): file.CopyToDirectory("directoryToPackage")
In this example, all .exe and .dll files will be copied to the “directoryToPackage” directory except for Phantom.exe
Here is an example from Phantom’s own build script:
with FileList("src/Phantom/bin/release"): .Include("*.{dll,exe}") .ForEach def(file): file.CopyToDirectory("build/release")
In this case, src/Phantom/bin/release is specified as the base directory and all .dll and .exe files will be copied directly into the output directory without copying any of the directory structure.
Note that directory structures are preserved when copying to the destination directory. If you do not want this behaviour, you can use the Flatten method to only copy the file to the destination directory without subdirectories.