import os def main(): fileList = os.listdir('.') for file in fileList: if file.startswith('slurm-'): command = 'scancel %s ' %file[6:12] print command os.system(command) if __name__ == '__main__': main()