i want to remove a file from my desktop .
i want to remove a file name (export.csv) from my desktop . I have code in python working fine for this.
Code :-
try:
import os
os.remove(r"C:\Users\zkhz8zd\Desktop\export.csv")
except Exception as e:
Log.Message(str(e)
Now I want it to make generic so that whoever run on there respective machine, it should work. I am using
Sys.UserName for this, however not able to do this.
I have changed ....os.remove(r"C:\Users\zkhz8zd\Desktop\export.csv") to os.remove(r"C:\Users\
+ str(Sys.UserName) +
\Desktop\export.csv")
Can anybody please help me with the code
Hi Amrendra,
You can get the desktop folder path as follows:
# TC 12+
desktop = WshShell.SpecialFolders.Item('Desktop')
# TC 11.x
desktop = Sys.OleObject['WScript.Shell'].SpecialFolders.Item('Desktop')This will work even on non-English versions of Windows and if it's installed on drives other than C:.
Then you can use os.path.join() to get the full file name:
os.remove( os.path.join(desktop, 'export.csv') )