Pywin32 Movefileex


Recommended Posts

Inspired by Matt's project i was seeing if I could use python to delete a file upon reboot. I am only able to rename it at reboot, I can't figure out the syntax to set the destination to null. Below is what works to rename the file

import win32file
import win32api

win32file.MoveFileEx("test.txt", "test2.txt" , win32file.MOVEFILE_DELAY_UNTIL_REBOOT)

how can I set the destination to null, to delete upon reboot?

Link to post
Share on other sites

I tried None without quotes, but it would not let me do it

C:/Python24/pythonw.exe -u  "C:/Documents and Settings/shane/Desktop/deletereboot.py"
Traceback (most recent call last):
File "C:/Documents and Settings/shane/Desktop/deletereboot.py", line 4, in ?
win32file.MoveFileEx("C:/Documents and Settings/shane/Desktop/test.txt", None , win32file.MOVEFILE_DELAY_UNTIL_REBOOT)
TypeError: None is not a valid string in this context

Link to post
Share on other sites
I was also using that for a reference, is it incorrect?

Can null be used as an argument somehow?

Use the win32api version of the function instead.

Incidentally, VB.NET is pretty much C# with different syntax and slightly different features. It's compiled to CIL bytecode and then JIT/AOT compiled to native by the .NET runtime.

Link to post
Share on other sites
I am not following you. Isn't that what I am using?

You used the win32file version in the code you posted. win32api and win32file export different MoveFileEx functions. I have no idea why.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...