VBScript can create text file but can't delete file (permission denied)? -


i create .vbs file (that can: creat text file -> open notepad.exe -> delete file above) this:

' create new file dim objfs, objfile set objfs = createobject("scripting.filesystemobject") set objfile = objfs.createtextfile("d:\folder\textfile.txt") objfile.writeline ("sample text")  ' run program , wait wscript.createobject("wscript.shell").run "notepad.exe", 1, true  ' delete file objfs.deletefile("d:\folder\textfile.txt") 

but when run it, after close notepad window, show error message:

line: 10 char: 1 error: permission denied code: 800a0046 source: microsoft vbscript runtime error 

i don't know why .vbs can't not delete text file? thank help!

you have close file handle in script before trying delete it.

' create new file dim objfs, objfile set objfs = createobject("scripting.filesystemobject") set objfile = objfs.createtextfile("d:\folder\textfile.txt")  'write file objfile.writeline ("sample text")  'close file objfile.close set objfile = nothing  ' open file in notepad, , wait wscript.createobject("wscript.shell").run "notepad.exe d:\folder\textfile.txt", 1, true  ' delete file objfs.deletefile("d:\folder\textfile.txt")  set objfs = nothing 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -