Data Access Worldwide Knowledge Base

Article ID 2061
Article Title INFO: Using Erasefile with a Blank Parameter
Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2061
KBase Category VDF (GENERAL)
Date Created 11/19/2004
Last Edit Date 11/19/2004


Article Text
QUESTION:
I used Erasefile in a program with an empty parameter and it erased all the files in my current directory.

The command I issued was:
Erasefile sMyFile   // sMyFile was "" at this point translating the command into Erasefile ""

Is that the expected behavior of erasefile? The documentation does not mention that.


ANSWER:
The erasefile command for Windows 2000 and higher is nothing more than the DEL DOS command using the parameter /Q. You can verify that by opening a command window at different workstations and typing:

Del "" /Q


Using the command prompt of a
1) Windows 2000 Pro
2) Windows XP
3) Windows NT 4.0 Server (cmd.exe and command.com)
4) Windows ME (without the /Q switch that does not exist on ME)

you will experience different behaviors. On 1, 2 and 3 all the files of the current directory will be deleted. On 4, an error occurs (missing parameter) and the files will not be removed.

If you then try to use erasefile "" in your program, the behavior you will experience will be the same as the behavior listed above for all the different Windows versions but Windows NT and ME.

On NT and ME, erasefile does NOT erase the files in the current directory. This is because a different implementation -- instead of DEL /Q --  is used if you run your program on pre-Windows 2000 operating systems.

A suggestion for eliminating this difference between operating systems was already logged in our systems.


Despite the differences described above, you should always add checks to your programs -- e.g. check if the parameter being passed to erasefile is not empty -- and use commands like Set_Directory and Get_Current_Directory to make sure you are using the right format of erasefile on the location/files you were expecting.  

As the documentation warns, "If Erasefile is executed on a non existent file, no error will be triggered" and "Erasefile provides no verification or protections unless you program them, and erroneous usage could potentially erase important data!"




Contributed By:
Marcia Booth
Company: Data Access Worldwide
Web Site: http://www.dataaccess.com


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.