Basically you want to list the files within a folder and perform an action for the command? So you don’t need to run a shell to run the python command just make python run the file listing and check that each file has the desired Substring.
Listing files within a directory:
from os import listdir
from os.path import isfile, join
apenasArquivos = [f for f in listdir(Caminho) if isfile(join(Caminho, f))]
,Checking each file listed with directory Caminho
has the substring FTP
for i in apenasArquivos :
if "FTP" in i:
# Executar ação
All these actions were executed through the module os
python. The modicum os
, has been specially developed for manipulations of the operating system, whatever it is.
the methods used above were the:
isfile
: Checks whether a given item is a file, returns True or false;
listdir
: list items in a directory;
join
: concatenates a path with the name of an item, thus generating an access path to the file;
You basically want to list the files you have
FTP
in the name inside this directory? If yes, why not do it directly with Python instead of setting a new process in the operating system to execute these commands?– Woss