Sponsored By

Sign in to follow this  
shanenin

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?

Share this post


Link to post
Share on other sites
win32file.MoveFileEx("...", None, win32file.MOVEFILE_DELAY_UNTIL_REBOOT)

Edited by jcl

Share this post


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

Share this post


Link to post
Share on other sites

Gah, I was looking at the ActivePython win32api.MoveFileEx.

Share this post


Link to post
Share on other sites
Gah, I was looking at the ActivePython win32api.MoveFileEx.

I was also using that for a reference, is it incorrect?

Can null be used as an argument somehow?

Edited by shanenin

Share this post


Link to post
Share on other sites

XP?

This is how its done in VB I believe:

MoveFileEx(szSrcFile, szDstFile, MOVEFILE_DELAY_UNTIL_REBOOT);

Example:

MoveFileEx( "C:\killme.exe", NULL, MOVEFILE_DELAY_UNTIL_REBOOT );

Share this post


Link to post
Share on other sites

the above code works with VB, I am trying to use python to call MoveFileEx. To be honest I do not really understand how vb works. Does it need to be compiled?

Share this post


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.

Share this post


Link to post
Share on other sites
Use the win32api version of the function instead.

I am not following you. Isn't that what I am using?

Share this post


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.

Share this post


Link to post
Share on other sites

I thnk I need to be spoon fed. Can you show me how you would code that?

huh?

import win32api
win32api.MoveFileEx()

Share this post


Link to post
Share on other sites
win32api.MoveFileEx("file", None, win32con.MOVEFILE_DELAY_UNTIL_REBOOT)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this