vbscript - Using file input element in hta file prevents deleting selected file -


if input html element of type=file used select file file cannot deleted hta program.

this mvce works doesn't use file dialog - have type filename in manually:

<html> <head> <script language="vbscript"> sub process     set x = createobject("scripting.filesystemobject")     msgbox "this delete "& inifile.value     x.deletefile inifile.value     msgbox "see? "& inifile.value &" gone"     set x = nothing end sub </script> </head> <body id='body'> <input type="text" name="inifile" > <input type="button" value="go!" onclick="process" > </body> </html> 

but mvce doesn't work - file not deleted; deferred until program exits:

<html> <head> <script language="vbscript"> sub process     set x = createobject("scripting.filesystemobject")     msgbox "try manually delete "& inifile.value &" (and undo it)"     x.deletefile inifile.value     msgbox "now try delete file "& inifile.value &" (now can't deleted until app closed)"     set x = nothing end sub </script> </head> <body id='body'> <input type="file" name="inifile" > <input type="button" value="go!" onclick="process" > </body> </html> 

somehow using file type input html element makes file can manually deleted outside program until deletefile function called. deletefile function doesn't delete file - deferrs deletion until hta program exits - @ point file deletes itself.

i need delete file while program still running. there way use file type input html element in hta file , still delete file while hta program running?

edit

my actual use case! in attempt produce usable mvce didn't realize solution found doesn't work particular requirements.

the reason deleting file can replace else, need file disappear before end of function. call window.location.reload() absolutely works file disappears @ end of function.

what trying this:

<html> <head> <script language="vbscript"> sub process     dim file: file = inifile.value     call window.location.reload()      'backup file tempfile.tmp     'now edit tempfile.tmp changes , preview     'then ask user whether happy changes     'delete original file     'and put tempfile.tmp in place      dim x: set x = createobject("scripting.filesystemobject")     x.copyfile file,"tempfile.tmp"     x.deletefile file     msgbox "why "& file &" still there?"     x.movefile "tempfile.tmp",file ' produces "file exists"     set x = nothing end sub </script> </head> <body id='body'> <input type="file" name="inifile" onchange="process"> </body> </html> 

use regular text input box

<input type="text" name="filename" size="30"> 

add button click open file

<input type="button" onclick="selectfile" value="browse..."> 

add file dialog object

<object id=dlg classid="clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b" width=0 height=0> 

add sub take return value of object , put in text box.

sub selectfile     filename.value = ""     strstartpath = "c:\test"     strfilter = "text (*.txt;*.csv)| *.txt;*.csv|vbscript (*.vbs;*.vbc)|*.vbs;*.vbc|html (*.htm;*.html;*.hta)|*.htm;*.html;*.hta|all files (*.*)|*.*|"     strcaption = "select file"     filename.value = dlg.openfiledlg(cstr(strstartpath), , cstr(strfilter), cstr(strcaption)) end sub 

the strstartpath, strfilter, , strcaption variables can excluded or customized needed.

filename.value contain path file , not locked.

edit:
here's entire hta, excluding code delete file (i have tested delete code):

<html> <head> <hta:application   applicationname="select file"   id="selectfileapplication"   version="1.0"/> <script language="vbscript">  sub selectfile     filename.value = ""     strstartpath = "c:\test"     strfilter = "text (*.txt;*.csv)| *.txt;*.csv|vbscript (*.vbs;*.vbc)|*.vbs;*.vbc|html (*.htm;*.html;*.hta)|*.htm;*.html;*.hta|all files (*.*)|*.*|"     strcaption = "select file"     filename.value = dlg.openfiledlg(cstr(strstartpath), , cstr(strfilter), cstr(strcaption))     'the file @ filename.value can deleted @ point. end sub  </script> </head> <body id="body"> <input type="text" name="filename" size="30"> <input type="button" onclick="selectfile" value="browse..."> <object id=dlg classid="clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b" width=0 height=0> </body> </html> 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo