I have a python script which I call through the .bat (batch) file. For the Python script to work I pass hardcoded arguments in the .bat file. But I need to pass the arguments dynamically as each time argument's value (name) would be different.
The python script's logic is not subject to my question, as it works properly. The question here is to how dynamically pass such arguments in the .bat file so that the specified in the same .bat file python script would except such dynamically passed arguments.
sys.argv[1] and sys.argv[1] are the arguments in the python file (see code below) which are hardcoded and passed in the .bat file. But I need to pass the arguments dynamically (as the the names will be different).
This is the .bat file that works properly as the arguments are hardcoded.
python "E:\Export\Test.py" "E:\Config\Test_Upload_10-15-2020.csv" "./Test_Upload_10-15-2020.csv" "E:\BulkInsert_DataAcquisition\SAM\Log"
The arguments are fully qualified file path and file name. "E:\Export\Test_Upload_10-15-2020.csv" is the sys.argv[1] "Test_Upload_10-15-2020.csv" is the sys.argv[2]
So I need to automate it to allow each csv file starting with the "Test_Upload_" to be processed.
I tried to replace the date stamp with the "" sign in the .bat (see code below) python "E:\Export\TEST.py" "E:\Config\Test_Upload_.csv" "./Test_Upload_*.csv" "E:\logFolderPath"
But I'm getting an error when execute this .bat file
Error occurred: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'E:\Export\Test_Upload_*.csv'
It works though with the exact file name "Test_10-15-2020.csv"
The Python script below works fine as long as I pass exact CVC name in the argumetns
import pysftp
import sys
import datetime
if __name__ == "__main__":
localFilePath = sys.argv[1] #"\\MyDBServer\E:\Config\Test_Upload_%.csv" % name
remoteFilePath = sys.argv[2] #"./Test_Upload_%.csv" % name.csv"
logFolderPath = sys.argv[3] #"E:\logFolderPath"
myHostname = "SFTP.MyWebSite.com"
myUsername = "MyLogin"
myPassword = "MyPassword"
try:
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword) as sftp:
print ("Connection succesfully stablished ... ")
sftp.put(localFilePath, remoteFilePath)
except Exception as e:
logfile = open(logFolderPath+"\Error_"+datetime.datetime.now().strftime("%Y%m%d_%H%M%S")+".log", "w")
logfile.write("Error occured: "+ str(e))
print(str(e))
logfile.close
sys.exit(1)