{"id":587,"date":"2011-07-27T20:46:01","date_gmt":"2011-07-27T20:46:01","guid":{"rendered":"http:\/\/craftydba.com\/?p=587"},"modified":"2024-02-17T14:25:37","modified_gmt":"2024-02-17T14:25:37","slug":"managing-files","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=587","title":{"rendered":"Managing Files"},"content":{"rendered":"<p>The most basic storage unit of any operating system is a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Computer_files\">file<\/a>. Files can contain anything from textual data in this article, a bitmap image of your baby daughter, a MS Excel worksheet containing your finances or a Visual Basic program you are currently working on. Therefore it is very important to know how to manipulate files after they are created.<\/p>\n<p>Common actions that are performed on files are copy, rename, move and delete. Each file has properties such as creation date, last date modified, and attributes such as read only. I have encapsulating the logic for working with files via <a href=\"http:\/\/en.wikipedia.org\/wiki\/VBScript\">File System Object<\/a> (FSO), into a abstract class.<\/p>\n<p>The Manage Files class has the following properties and methods.<\/p>\n<ul>\n<li>SetFn &#8211; Set the full path of a workable file.<\/li>\n<li>CopyFn &#8211; Copy the file to a new destination.<\/li>\n<li>MoveFn &#8211; Move the file to a new location.<\/li>\n<li>DeleteFn &#8211; Remove the file from a current location.<\/li>\n<li>ExistFn &#8211; Test the existance of a file.<\/li>\n<li>GetFileName &#8211; Return the file name w\/o path.<\/li>\n<li>GetDirName &#8211; Return the path w\/o file name.<\/li>\n<li>GetLastAccess &#8211; Time of this event.<\/li>\n<li>GetDateCreated &#8211; Time of this event<\/li>\n<li>GetLastModifiied &#8211; Time of this event.<\/li>\n<li>GetFileSizeInBytes &#8211; Return the file size.<\/li>\n<li>GetFileAttributes &#8211; Get the attributes such as read only.<\/li>\n<li>SetFileAttributes &#8211; Set the attributes such as read only.<\/li>\n<li>MakeFileStamp &#8211; Return\u00a0current time in mmddyy &#8211; hhmmss format.<\/li>\n<\/ul>\n<p>The following actions are carried out in the test program to give you a good idea of what can be functionally done.<\/p>\n<ol>\n<li>Set File Name to file0<\/li>\n<li>Show file name<\/li>\n<li>Show directory name<\/li>\n<li>Show Size<\/li>\n<li>Show Date Created<\/li>\n<li>Show Date Accessed<\/li>\n<li>Show Date Modified<\/li>\n<li>Show Attributes<\/li>\n<li>Copy file0 to directory 2 as file1<\/li>\n<li>Copy file0 to directory 2 as file2<\/li>\n<li>Copy file0 to directory 2 as file3 with timestamp<\/li>\n<li>Move file2 to directory 1<\/li>\n<li>Make file0 read only<\/li>\n<li>Try to delete file0<\/li>\n<\/ol>\n<p>A great application of this class would be the archiving of inbound <a href=\"http:\/\/en.wikipedia.org\/wiki\/FTP\">FTP<\/a> files after uploading to a SQL Server database via an <a href=\"http:\/\/en.wikipedia.org\/wiki\/Extract,_transform,_load\">ETL<\/a> program written in VB Script. Managing files and directories is a key element of any data driven application. Having classes that perform these actions reduces the time to develop a business solution.<\/p>\n<p>The table below has starter code that you can use in your next Visual Basic (VB) Script<\/p>\n<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\" width=\"600\" align=\"left\">\n<tbody>\n<tr>\n<td style=\"border: thin solid gray;\"><a href='https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/mod-manage-files.vbs_.txt'>mod-manage-files.vbs<\/a>\n<\/td>\n<td style=\"border: thin solid gray;\">Manage Files Class<\/td>\n<\/tr>\n<tr>\n<td style=\"border: thin solid gray;\"><a href='https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/tst-manage-files.vbs_.txt'>tst-manage-files.vbs<\/a><\/td>\n<td style=\"border: thin solid gray;\">Sample Program<\/td>\n<\/tr>\n<tr>\n<td style=\"border: thin solid gray;\"><a href='https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/manage-files.cmd_.txt'>manage-files.cmd<\/a><\/td>\n<td style=\"border: thin solid gray;\">Batch Program<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/P><\/p>\n<p>&nbsp;<\/P><\/p>\n<p>&nbsp;<\/P><\/p>\n<p>&nbsp;<\/P><\/p>\n<p>&nbsp;<\/P><\/p>\n<p>The output below was generated by the execution of the test program.<\/p>\n<p>&nbsp;<\/P><\/p>\n<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/manage-files.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/manage-files-300x177.jpg\" alt=\"\" title=\"manage-files\" width=\"300\" height=\"177\" class=\"alignleft size-medium wp-image-613\" srcset=\"https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/manage-files-300x177.jpg 300w, https:\/\/craftydba.com\/wp-content\/uploads\/2011\/07\/manage-files.jpg 674w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/P><\/p>\n<p>&nbsp;<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The most basic storage unit of any operating system is a file. Files can contain anything from textual data in this article, a bitmap image of your baby daughter, a MS Excel worksheet containing your finances or a Visual Basic program you are currently working on. Therefore it is very important to know how to manipulate files after they are created. Common actions that are performed on files are copy, rename, move and delete. Each file has properties such as creation date, last date modified, and attributes such as read&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[35,36,12,15,13,19],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-other","tag-file-system-object","tag-files","tag-free-code","tag-john-f-miner-iii","tag-vb-script-2","tag-xls-file"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=587"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/587\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}