Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7793095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:22:37+00:00 2026-06-01T22:22:37+00:00

I have a small app using Drive.Info. I want to do two things. Check

  • 0

I have a small app using Drive.Info. I want to do two things. Check a certain drive exists on a machine, and if it does and todaysdate isn’t one of a number of dates stored in a text file, run a small application. If today’s date is read inside the text file, do nothing. I Have a bunch of code working but having trouble with the DateTime object. Can anyone take a look at what I have and advise what I need to restructure? All the logic is there, I’m just not putting it together correctly.

  1. Dates stored in the txt file I’m reading from are like so on each
    line: 25/12/2010.
  2. Inside the catch statement the line “Console.WriteLine(e.Message);” is what is generating the ” String was not recognised as a valid DateTime” issue.
  3. My desired goal is: If today’s date is NOT found in the text file & The drive specified at the line “(d.Name.Contains(“C”))” exists on the current machine, run calc.exe.
  4. If today’s date IS found in the text file, do nothing.

My issue is: How do I modify the structure of my application so I can: compare dates successfully with those stored in the txt file. And secondly, adjust my logic so I can achieve parts 3 & 4 above.

Apologies for needing to edit, I should have been more clear with my initial post.
Thanks.

EDIT: Guys I’ve updated the code below. It seems to be working now. Thanks for the help and sorry again for the poorly put together first question. The application behaviour is working as desired now, however; the catch is still being hit (when today’s date is not in the file, and the specified drive does not exist) It would be nice to understand why this is happening?

public static void Main()
/* Goal of this application: Read a text file filled with public holiday dates     formatted as: 25/12/2011
 * Compare these to today's date.  If not a match, run calc.exe ASSUMING THE SPECIFIED   DRIVE ON LINE 78
 * IS FOUND ON THE COMPUTER.  If the date matches, do nothing.
*/
{
    Process Calculator = new Process();
    Calculator.StartInfo.FileName = "calc.exe";
    Calculator.StartInfo.Arguments = "ProcessStart.cs";
    DriveInfo[] allDrives = DriveInfo.GetDrives();

    // Create a StreamReader to read from file.
    StreamReader sr = new StreamReader("file.txt");

        String DateFromFile;
        DateTime todaysDate = DateTime.Today;

        try
        {              
            // Read and display lines from the file until the eof is reached.
            while ((DateFromFile = sr.ReadLine()) != null)
            {
                Console.WriteLine(DateFromFile);
                DateTime dt = Convert.ToDateTime(DateFromFile);


                if (dt == todaysDate)
                {
                    Console.WriteLine("File.text has todays date inside! Not gonna run calc.exe");
                    Environment.Exit(0);

                }//end if 

                else
                {
                 }//end else


          }//end while
        }//end try

        catch (Exception e)
        {
            // Let the user know what went wrong.
            Console.WriteLine("The file.txt could not be read");
            Console.WriteLine(e.Message);
       }

        ////////// DO THE REST ///////////
     foreach (DriveInfo d in allDrives)
        {
            Console.WriteLine("Drive {0}", d.Name);

            Console.WriteLine("  File type: {0}", d.DriveType);
            if (d.IsReady == true)
            {
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
                Console.WriteLine("  File system: {0}", d.DriveFormat);
                Console.WriteLine(
                    "  Available space to current user:{0, 15} bytes",
                    d.AvailableFreeSpace);

                Console.WriteLine(
                    "  Total available space:          {0, 15} bytes",
                    d.TotalFreeSpace);

                Console.WriteLine(
                    "  Total size of drive:            {0, 15} bytes ",
                    d.TotalSize);
            }//end if
            if (d.Name.Contains("T"))
            {
                Console.WriteLine("\n");
                Console.WriteLine("** SUCCESS - LETTER FOUND **\n\n ** RUN CALC.EXE **");
                Console.WriteLine("\n");
                Calculator.Start();
            }//end if
            else
            {
                Console.WriteLine("** LETTER NOT FOUND **");
                Console.WriteLine("\n");
            }//end else  
        }//end for


}//end main
}//end class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:22:39+00:00Added an answer on June 1, 2026 at 10:22 pm

    I think you have to get the current date at the beginning to particular date format.

    As e.g. Use

    String todaysDate = DateTime.Now.ToShortDateString();
    

    And when you compare also convert the string to that format and compare

     String dt = DateTime.Parse(DateFromFile).ToShortDateString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively small app that Im building using vb.net 2.0, and nant.
I'm using BerkeleyDB to develop a small app. And I have a question about
I have a small app that has a Render thread. All this thread does
I have small TcpClient app to connect to a server using SSL (SSlStream class)
I have a small app I've written, and it works well when using the
I have a small MVC 3 app using Entity Framework Code First and use
Using PHP.. I have a small app that I built that currently uses a
I have a small app using omniauth and I'm testing it with LinkedIn provider
I have a small app using RestKit with a Sinatra-backed server. When I post
I have built a small app using javascript. I am using javascript for form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.