28 lines
		
	
	
		
			687 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			687 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python
 | 
						|
import sys, os
 | 
						|
 | 
						|
if sys.argv[1] in ["--help", "-h"]:
 | 
						|
    print("\nWelcome to the cli helper for foreach loops.")
 | 
						|
    print("\nUsage:\neachf [path] [filter] [command1] [command2]")
 | 
						|
    print("\nDescription:\nIn between the two command-arguments, the filename will be inserted.\n")
 | 
						|
    exit()
 | 
						|
 | 
						|
files = os.listdir(sys.argv[1])
 | 
						|
filtered_files = []
 | 
						|
commands = []
 | 
						|
 | 
						|
 | 
						|
for file in files:
 | 
						|
    if sys.argv[2] in file:
 | 
						|
        filtered_files.append(file)
 | 
						|
 | 
						|
for f in filtered_files:
 | 
						|
    if len(sys.argv) == 4:
 | 
						|
        c = sys.argv[3] + " " + f
 | 
						|
    else:
 | 
						|
        c = sys.argv[3] + " " + f + " " + sys.argv[4]
 | 
						|
    commands.append(c)
 | 
						|
    
 | 
						|
for command in commands:
 | 
						|
    os.system(command)
 |