We want to delete some subdirectories in our MyFolder directory. The following code example deletes MyFolder2 and MyFolder4 using the Directory.Delete() method, which accepts a path to the folder that we want it to delete.
There is nothing special about this code except that we have used the String.SubString() method to return the last character in the directory name. That character is a number, so we have converted it from a string data type to an int data type. The if statement evaluates to true if the returned value of the expression dirNum % 2 is 0. So only the folders MyFolder2 and MyFolder4 are deleted because 2 % 2 == 0 and 4 % 2 = 0.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |