shanenin Posted June 20, 2006 Report Share Posted June 20, 2006 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 fileimport win32fileimport win32apiwin32file.MoveFileEx("test.txt", "test2.txt" , win32file.MOVEFILE_DELAY_UNTIL_REBOOT)how can I set the destination to null, to delete upon reboot? Quote Link to post Share on other sites
jcl Posted June 20, 2006 Report Share Posted June 20, 2006 (edited) win32file.MoveFileEx("...", None, win32file.MOVEFILE_DELAY_UNTIL_REBOOT) Edited June 20, 2006 by jcl Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 I tried None without quotes, but it would not let me do itC:/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 Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 Gah, I was looking at the ActivePython win32api.MoveFileEx. Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 (edited) 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 June 21, 2006 by shanenin Quote Link to post Share on other sites
Matt Posted June 21, 2006 Report Share Posted June 21, 2006 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 ); Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 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? Quote Link to post Share on other sites
Matt Posted June 21, 2006 Report Share Posted June 21, 2006 I don't know VB either. It does need to be compiled. Did you try NULL in the python script? Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 I tried it, among any other possible variation. Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 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. Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 Use the win32api version of the function instead.I am not following you. Isn't that what I am using? Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 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. Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 I thnk I need to be spoon fed. Can you show me how you would code that?huh?import win32apiwin32api.MoveFileEx() Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 win32api.MoveFileEx("file", None, win32con.MOVEFILE_DELAY_UNTIL_REBOOT) Quote Link to post Share on other sites
shanenin Posted June 21, 2006 Author Report Share Posted June 21, 2006 (edited) Thanks :-) Edited June 21, 2006 by shanenin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.