Creating a Formatted Numeric Prefix to Rename Files
Posted on 2006-05-10
I've written a program to copy files from one drive to the next. It works great so far, but I'm having trouble creating the file prefix I want to make. My question is on how to do this. Please read through the entire post.
I have a textbox in which the user will specify what the prefix can be. The user can type in something like:
Basically, I want to be able to check the string to make sure it contains exactly one valid format (i.e. #, 0#, 00#, etc. but not a 0 by itself) and use that to format the number using the function: Format(expression,format). The positioning of the format does not matter, as long as it's part of the string (the string value is specified from the textbox explained from the previous paragraph). I also want to attach a before and after string to this number (Note in this example, the letter "T" before the zero(s) and the dash ('-') after the pound sign). Before and after strings can be null (i.e. if I wanted to make the prefix a number only).
Here is sample output with the filename originally being Filename.txt.
Overall, my question is, how do I take the textbox value, extract the format, validate the format and then reattach all of it together? What is the easiest way to do this? Please provide some code. Thanks.
Random Thought: Do I need a beginning, middle and end string? An array?
Note that I'm using the File.Copy method to copy from source to destination.