Search code examples
scons

Scons Copying File on Changes?


Well i have some extra text files, with different extensions, and i need them to be copied to the bin. Right now i am using:

files = []

for root, dirs, files in os.walk("extra_src"):
    for file in files:
        files.append(["extra_src" + os.sep + file, "bin" + os.sep + file])


for element in files:
    command = Command(target = element[1], source = element[0], action = Copy("$TARGET", "$SOURCE"))
    Requires(program, command)

Is there any other way to get it to register the files and simply specify all the files in a said directory? I can use Command(..., Copy("dir1", "dir2")) but it doesn't detect changes, and doesn't clean out the bin of those files.


Solution

  • Try something along the lines of:

    import os # for os.path.join
    
    inst = env.Install('bin', Glob(os.path.join('extra_src','*.*')))
    env.Depends(program, inst) # if required
    

    Note, how the Glob() function will even find files that don't exist yet, but get created by another build step.