Hey Guys!
I'm new to python and I've got only basic knowledge in the programming language that's why I'm turning to you. I work with MS SQL and .NET framework only. But now I want to make a script that moves firstly.
Counts the number of files in the directory.
Second it loops by taking one file at the time.
Doing the following steps.
Takes 1 file renaming it --> Moving it to other folder.
Executing stored procedure --> deleting the file as last step.
So far this is my code,I'm getting two errors first is that it requires more arguments and second is that the file cannot be found.
I've spent days on this script and getting really tired of it, so any help would be very appriciated.
I'm new to python and I've got only basic knowledge in the programming language that's why I'm turning to you. I work with MS SQL and .NET framework only. But now I want to make a script that moves firstly.
Counts the number of files in the directory.
Second it loops by taking one file at the time.
Doing the following steps.
Takes 1 file renaming it --> Moving it to other folder.
Executing stored procedure --> deleting the file as last step.
So far this is my code,I'm getting two errors first is that it requires more arguments and second is that the file cannot be found.
I've spent days on this script and getting really tired of it, so any help would be very appriciated.
Code:
import os
import shutil
import glob
import pyodbc
import os.path
#Counts the files
def filecount(dir_name):
dir_name = 'D:\Applications\Prod\IMP\Software'
return len([f for f in os.listdir(dir_name) if os.path.isfile(f)])
filecount()
#Renaming
while (f > 0):
def main():
d = 'D:\Applications\Prod\IMP\Software'
file = glob.glob('*.CSV')
for file in os.listdir(d):
title = 'Dialer_Import_ABC'
if file.endswith(".csv"):
os.rename(file,title+".csv")
main()
#Moving the files
def flytt():
destination = '\\sesrv413\f$\BulkInsert\Folder'
source = 'D:\Applications\Prod\IMP\Software'
file = 'D:\Applications\Prod\IMP\Software'\Dialer_Import_ABC.csv'
if file('D:\Applications\Prod\IMP\Software'\Dialer_Import_ABC.csv'):
shutil.move(destination, source)
flytt()
#Kör SP #UID=se.dialog.inv;PWD=Ajax123' vet ej om det behövs
def SP():
cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=sesrv413;DATABASE=Maintenance")
cursor = cnxn.cursor()
cursor.execute("exec maintenance.dbo.PD_ABC_SP")
SP()
# Removing files
def bort():
myfile ="\\sesrv413\f$\BulkInsert\Folder\Dialer_Import_ABC.csv"
if os.path.isfile(myfile):
os.remove(myfile)
bort()
Comment