Testing a console applications input / Testing a files existence 
Author Message
 Testing a console applications input / Testing a files existence

I am trying to decide on the best way to test a string which is entered by a user in a console application is:
  a.. A valid file name
  b.. That that file exists and is either a bmp, gif, jpg etc.
Here's a quick snippet of what I want to do. I really want  to know what people think is the best way to code this peice of info. I want to be able to return the user a message telling them what the specific error was.

User at console

d:>test /src:c:\inetpub\wwwroot\im\skimming.jpg /w:100 /h:100

Test.cs
foreach (string arg in args)
  {
   string lower = arg.ToLower();

  if (lower.StartsWith("/src:"))
    {
                       srcFile = arg.Substring(5);
                  }
   else if (lower.StartsWith("/h:"))
    {
                       string DestHeight  = arg.Substring(3);
     dHeight = Convert.ToInt32(dHeight);
                  }                
   else if (lower.StartsWith("/w:"))
    {
     string DestWidth  = arg.Substring(3);
     dWidth = Convert.ToInt32(dWidth);
    }
  }

//test src file
    //srcFile = IS THIS A VALID FILE STRING USING REGULAR EXPRESSIONS

    //srcFile = DOES THIS FILE EXIST AS A FILE



Sun, 01 Aug 2004 06:33:14 GMT  
 Testing a console applications input / Testing a files existence

Sounds obvious i spose but why not just try to open the file inside a try-catch block and give a plain english response for the error if any?

Bob.

  I am trying to decide on the best way to test a string which is entered by a user in a console application is:
    a.. A valid file name
    b.. That that file exists and is either a bmp, gif, jpg etc.
  Here's a quick snippet of what I want to do. I really want  to know what people think is the best way to code this peice of info. I want to be able to return the user a message telling them what the specific error was.

  User at console

  d:>test /src:c:\inetpub\wwwroot\im\skimming.jpg /w:100 /h:100

  Test.cs
  foreach (string arg in args)
    {
     string lower = arg.ToLower();

    if (lower.StartsWith("/src:"))
      {
                         srcFile = arg.Substring(5);
                    }
     else if (lower.StartsWith("/h:"))
      {
                         string DestHeight  = arg.Substring(3);
       dHeight = Convert.ToInt32(dHeight);
                    }                
     else if (lower.StartsWith("/w:"))
      {
       string DestWidth  = arg.Substring(3);
       dWidth = Convert.ToInt32(dWidth);
      }
    }

  //test src file
      //srcFile = IS THIS A VALID FILE STRING USING REGULAR EXPRESSIONS

      //srcFile = DOES THIS FILE EXIST AS A FILE



Sun, 01 Aug 2004 08:19:32 GMT  
 Testing a console applications input / Testing a files existence
Hi Scott,

I would use the System.IO namespace. Since you need to check for particular
extensions, I would create a DirectoryInfo object and then use its
GetFiles() method. Another alternative would be to add each extension in
turn and use File.Exists().

Hope this is helpful.

--
Jeff Rhodes
Platte Canyon Multimedia Software Corporation


I am trying to decide on the best way to test a string which is entered by a
user in a console application is:
A valid file name
That that file exists and is either a bmp, gif, jpg etc.
Here's a quick snippet of what I want to do. I really want  to know what
people think is the best way to code this peice of info. I want to be able
to return the user a message telling them what the specific error was.

User at console

d:>test /src:c:\inetpub\wwwroot\im\skimming.jpg /w:100 /h:100

Test.cs
foreach (string arg in args)
  {
   string lower = arg.ToLower();

  if (lower.StartsWith("/src:"))
    {
                       srcFile = arg.Substring(5);
                  }
   else if (lower.StartsWith("/h:"))
    {
                       string DestHeight  = arg.Substring(3);
     dHeight = Convert.ToInt32(dHeight);
                  }
   else if (lower.StartsWith("/w:"))
    {
     string DestWidth  = arg.Substring(3);
     dWidth = Convert.ToInt32(dWidth);
    }
  }

//test src file
    //srcFile = IS THIS A VALID FILE STRING USING REGULAR EXPRESSIONS

    //srcFile = DOES THIS FILE EXIST AS A FILE



Sun, 01 Aug 2004 09:16:24 GMT  
 Testing a console applications input / Testing a files existence

FileInfo fileInfo = new FileInfo(filename);

if (!fileInfo.Exists)
{

Quote:
}

--
This posting is provided "AS IS" with no warranties, and confers no rights.


  I am trying to decide on the best way to test a string which is entered by a user in a console application is:
    a.. A valid file name
    b.. That that file exists and is either a bmp, gif, jpg etc.
  Here's a quick snippet of what I want to do. I really want  to know what people think is the best way to code this peice of info. I want to be able to return the user a message telling them what the specific error was.

  User at console

  d:>test /src:c:\inetpub\wwwroot\im\skimming.jpg /w:100 /h:100

  Test.cs
  foreach (string arg in args)
    {
     string lower = arg.ToLower();

    if (lower.StartsWith("/src:"))
      {
                         srcFile = arg.Substring(5);
                    }
     else if (lower.StartsWith("/h:"))
      {
                         string DestHeight  = arg.Substring(3);
       dHeight = Convert.ToInt32(dHeight);
                    }                
     else if (lower.StartsWith("/w:"))
      {
       string DestWidth  = arg.Substring(3);
       dWidth = Convert.ToInt32(dWidth);
      }
    }

  //test src file
      //srcFile = IS THIS A VALID FILE STRING USING REGULAR EXPRESSIONS

      //srcFile = DOES THIS FILE EXIST AS A FILE



Sun, 01 Aug 2004 13:44:12 GMT  
 Testing a console applications input / Testing a files existence
Please consider setting your news client to send "Plain Text" for public
newsgroups.  Your formatted text came across on my monitor as about 1/64"
high, and even with my reading glasses on, I can't make out what you're
saying.

If you send plain text, which is considered proper netiquette, then we'll
all see your message according to OUR choices of font and size, and be
better able to understand what you're saying.

Thanks!

    Jerry in Bothell


I am trying to decide on the best way to test a string which is entered by a
user in a console application is:
  a.. A valid file name
  b.. That that file exists and is either a bmp, gif, jpg etc. ...



Fri, 06 Aug 2004 04:34:39 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. test test test test

2. test for file existence?

3. Test for file existence

4. test...test...test

5. Testing for directory existence - How?

6. testing a directory's existence

7. this is a test message - testing my email program - please ignore it - thank you -bye

8. testing testing

9. How to test (Re: C language test)

10. VC++5: Creating library .\Debug/Test.lib and object .\Debug/Test.exp

11. Test if input is integer within range

12. total newbie: how to test user input to see if its an float or integer

 

 
Powered by phpBB® Forum Software