{"id":329,"date":"2006-11-27T07:00:00","date_gmt":"2006-11-27T15:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2006\/11\/27\/save-me\/"},"modified":"2006-11-27T07:00:00","modified_gmt":"2006-11-27T15:00:00","slug":"save-me","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2006\/11\/27\/save-me\/","title":{"rendered":"Save Me!"},"content":{"rendered":"<p>A few days ago I showed how to call an Open File dialog box. I promised to show you how to let a user specify a filename and path by browsing using the File dialog box.&nbsp; This is much better than using an input box, especially when you want to save the file to a specific folder where you don&#8217;t know the full path off the top of your head.&nbsp; Here&#8217;s a sample script.<\/p>\n<p><span style=\"font-family: Courier New,Courier,mono;\">&#8216;SaveAsDemo.vbs<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&#8216;specify a default filename<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">strFile=SaveAs(&#8220;C:\\demo.txt&#8221;)<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">If strfile&lt;&gt;&#8221;&#8221; Then WScript.Echo &#8220;Saving as &#8221; &amp; strFile<\/span><br style=\"font-family: Courier New,Courier,mono;\"><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&#8216;don&#8217;t specify a filename but set parameter to blank<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">strFile=SaveAs(&#8220;&#8221;)<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">If strfile&lt;&gt;&#8221;&#8221; Then WScript.Echo &#8220;Saving as &#8221; &amp; strFile<\/span><br style=\"font-family: Courier New,Courier,mono;\"><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&#8216;**********************************<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&#8216;*&nbsp; File SaveAS Function&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; *<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&#8216;**********************************<\/span><br style=\"font-family: Courier New,Courier,mono;\"><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">Function SaveAs(strFile)<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&#8216;This requires Windows XP\/2003<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; Set objDialog=CreateObject(&#8220;SAFRCFileDlg.FileSave&#8221;)<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; objDialog.filename=strFile<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; objDialog.OpenFileSaveDlg<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; SaveAs=objDialog.FileName<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">End Function<\/span><br style=\"font-family: Courier New,Courier,mono;\"><br \/>The object we&#8217;re using in the function is almost the same as what we used to open a file. The function as written requires a default vault value, even if it is blank.&nbsp; If you select an existing file, you&#8217;ll get an warning about overwriting the file.&nbsp; But nothing really happens. The function will return the full path and filename of whatever you select and that&#8217;s it.&nbsp; You still need to use something like the FileSystemObject to create the file. This function simply makes it easier for a user to browse to folder and specify a file name instead of having to type it into an input box.<\/p>\n<p>I prefer providing a default filename and path, expecting that in most cases it will be sufficient and all the user has to do is click Save. <\/p>\n<p>Now you have some flexibility to offer your users when it comes to finding or specifying files and your scripts can look more like Windows utilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I showed how to call an Open File dialog box. I promised to show you how to let a user specify a filename and path by browsing using the File dialog box.  This is much better than using an input box, especially when you want to save the file to a specific folder where you don&#8217;t know the full path off the top of your head.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,24],"tags":[],"class_list":["post-329","post","type-post","status-publish","format-standard","hentry","category-general","category-vbscript"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}