2

When I run a script in Windows Task Scheduler, I got

[Errno 22] invalid mode ('wb') or filename:
'\\172.16.60.16\\\xf1\xee\xba\xcf\\lantian\\FAC\\FAC\xbb\xe3\xd7\xdc\xca\xfd\xbe\xdd\xd4\xb4\\F17\xba\xc5\xbb\xfa\xcc\xa8\xd2\xec\xb3\xa3\xbc\xc7\xc2\xbc\xb1\xed.csv

but I run it in IDLE and console was fine. code down there:

record_dir = r"D:\Record"
target_dir = r"\\172.16.60.16\耦合\lantian\FAC\FAC汇总数据源"
file_path = os.path.join(record_dir, filename)
target_path = os.path.join(target_dir, filename)
shutil.copyfile(file_path, target_path)

Is it an encoding problem?

I've tried to convert target_path to unicode, but that doesn't work, either.

TylerH
  • 20,799
  • 66
  • 75
  • 101
VinceYang
  • 21
  • 3

2 Answers2

0

In this condition,it was the path of share which somehow can't access by Windows task scheduler.So i use net use \\172.16.60.16\耦合 every time before i copy file to this share to get this script can access this share.And finally,it works. FYI: in my script the code like this:

delete_drive_cmd = r"net use * /DEL /Y"
create_drive_cmd = r"net use \\172.16.60.16\耦合 /PERSISTENT:NO"
os.system(delete_drive_cmd)
os.system(create_drive_cmd)

and here is the website where i get answer: "https://social.technet.microsoft.com/Forums/en-US/d47d116e-10b9-44f0-9a30-7406c86c2fbe/scheduled-task-wont-run-bat-file?forum=winservermanager"

VinceYang
  • 21
  • 3
-1

The "r" removes the double "\" before the ip address you are trying to access. Try to debug the issue using os.path.exists() on the folder you are writing to.

Roy Segal
  • 11
  • 1