Managing Files

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 only. I have encapsulating the logic for working with files via File System Object (FSO), into a abstract class.

The Manage Files class has the following properties and methods.

  • SetFn – Set the full path of a workable file.
  • CopyFn – Copy the file to a new destination.
  • MoveFn – Move the file to a new location.
  • DeleteFn – Remove the file from a current location.
  • ExistFn – Test the existance of a file.
  • GetFileName – Return the file name w/o path.
  • GetDirName – Return the path w/o file name.
  • GetLastAccess – Time of this event.
  • GetDateCreated – Time of this event
  • GetLastModifiied – Time of this event.
  • GetFileSizeInBytes – Return the file size.
  • GetFileAttributes – Get the attributes such as read only.
  • SetFileAttributes – Set the attributes such as read only.
  • MakeFileStamp – Return¬†current time in mmddyy – hhmmss format.

The following actions are carried out in the test program to give you a good idea of what can be functionally done.

  1. Set File Name to file0
  2. Show file name
  3. Show directory name
  4. Show Size
  5. Show Date Created
  6. Show Date Accessed
  7. Show Date Modified
  8. Show Attributes
  9. Copy file0 to directory 2 as file1
  10. Copy file0 to directory 2 as file2
  11. Copy file0 to directory 2 as file3 with timestamp
  12. Move file2 to directory 1
  13. Make file0 read only
  14. Try to delete file0

A great application of this class would be the archiving of inbound FTP files after uploading to a SQL Server database via an ETL 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.

The table below has starter code that you can use in your next Visual Basic (VB) Script

mod-manage-files.vbs Manage Files Class
tst-manage-files.vbs Sample Program
manage-files.cmd Batch Program





The output below was generated by the execution of the test program.




Related posts

4 Thoughts to “Managing Files”

  1. You’ve got a a nice bunch of posts here now. Keep it up..

  2. Sup. Just wanted to give a quick mention and tell you that I’ve loved visiting your personal website and will be recommending it to my acquaintances. Keep up the good work! Thanks.

  3. Howdy! You some kind of professional? Nice message. Are you able to tell me how one can subscribe your weblog?

  4. Great post. I was checking constantly this blog and I am inspired! Very helpful information specially the closing section :) I care for such info a lot. I used to be looking for this certain information for a very lengthy time. Thank you and best of luck.

Leave a Comment