Checking newer Zip file

by looking at the date in the filename

Page 1 of 1

6 Replies - 727 Views - Last Post: 13 January 2011 - 06:40 AM Rate Topic: -----

#1 MarmiteX1  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 17-October 09

Checking newer Zip file

Posted 21 December 2010 - 01:10 PM

Hi there,

Hope you are well?

I am currently working on a application and I am trying to extract contents from a Zip file. The zip file contains images and a text file of ID's which correspond to each Animal image.

I am having an issue detecting a newer file.

The zip file that I am processing is structured in the following format:

LLL_IMAGES_LLLLLLLL-DDMMYYYY.zip

As you can see the Date format is DDMMYYYY. How could I go about detecting this date and comparing it todays date? Regular expressions?

Now i came across the following and I took out the "/" so could this potentially work?
^([01]\d)([0-3]\d)(\d{4})$



I would appreciate if anyone could provide any thoughts on the above please?

Thanks in advance,

Is This A Good Question/Topic? 0
  • +

Replies To: Checking newer Zip file

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9574
  • View blog
  • Posts: 36,262
  • Joined: 12-June 08

Re: Checking newer Zip file

Posted 21 December 2010 - 01:18 PM

That or take off the right four characters (".zip") and then keep the sub string of the next eight (MMDDYYYY)... and then break that apart by the locations into three substrings ("MM", "DD", "YYYY").

Something like this:
        '"LLL_IMAGES_LLLLLLLL-DDMMYYYY.zip"
        Dim foo As String = "LLL_IMAGES_LLLLLLLL-01122010.zip"

        Console.WriteLine(foo) 'LLL_IMAGES_LLLLLLLL-01122010.zip
        foo = foo.Substring(0, foo.Length - 4)
        Console.WriteLine(foo) 'LLL_IMAGES_LLLLLLLL-01122010
        foo = foo.Substring(foo.Length - 8, 8)
        Console.WriteLine(foo) '01122010
        Dim myTime As New DateTime(foo.Substring(4, 4), foo.Substring(2, 2), foo.Substring(0, 2))
        Console.WriteLine(myTime) '12/1/2010 12:00:00 AM


Arg.. I forget people don't vacillate between VB and C# as easy as some.
            //"LLL_IMAGES_LLLLLLLL-DDMMYYYY.zip"
            string foo = ("LLL_IMAGES_LLLLLLLL-01122010.zip");
            Console.WriteLine(foo); //LLL_IMAGES_LLLLLLLL-01122010.zip
            foo = foo.Substring(0, foo.Length - 4);
            Console.WriteLine(foo); //LLL_IMAGES_LLLLLLLL-01122010
            foo = foo.Substring(foo.Length - 8, 8);
            Console.WriteLine(foo); //01122010;
            DateTime myTime = new DateTime(Convert.ToInt32(foo.Substring(4, 4)),
                                       Convert.ToInt32(foo.Substring(2, 2)),
                                         Convert.ToInt32(foo.Substring(0, 2)));
            
            Console.WriteLine(myTime); //12/1/2010 12:00:00 AM

This post has been edited by modi123_1: 21 December 2010 - 03:43 PM

Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Checking newer Zip file

Posted 21 December 2010 - 03:31 PM

In C#:

string fileName = "LLL_IMAGES_LLLLLLLL-01122010.zip";

string month = fileName.Substring(fileName.Length - 12, 2);
string day = fileName.Substring(fileName.Length - 10, 2);
string year = fileName.Substring(fileName.Length - 8, 4);

DateTime theDate = new DateTime(month, day, year);
Console.WriteLine(theDate.ToString());




NOT TESTED. But should work, give it a shot.
Was This Post Helpful? 0
  • +
  • -

#4 itpro4470  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 156
  • Joined: 17-June 07

Re: Checking newer Zip file

Posted 21 December 2010 - 07:12 PM

Your regex should also work. Take off the ^ and the $. There is actually a function of the DirectoryInfo class that will allow you to find all files in a folder that match a regular expression this has been very useful for me.

Sorry I didn't read your post all the way you're original regex should work then you can use DateTime.parseExact("ddMMyyyy") to get a DateTime then compare away!

This post has been edited by itpro4470: 21 December 2010 - 07:18 PM

Was This Post Helpful? 0
  • +
  • -

#5 MarmiteX1  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 17-October 09

Re: Checking newer Zip file

Posted 22 December 2010 - 08:50 AM

Hi,

Thanks for the suggestion(s) but I am having an issue with creating a valid DateTime Object:

I can access the values from the file using Substring method but I want to create a DateTime from the string.

This is what I have done so far:

DateTime test = DateTime.ParseExact("ddMMyyyy", extractedDate,CultureInfo.CurrentCulture,DateTimeStyles.None);


extractedDate contains value in format ddmmyyyy.

Any thoughts?

Thanks,
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9574
  • View blog
  • Posts: 36,262
  • Joined: 12-June 08

Re: Checking newer Zip file

Posted 22 December 2010 - 09:09 AM

You need to add the appropriate breaks between the dd, mm, and yyyy. Something like "dd/mm/yyyy" or "dd-mm-yyyy".
Was This Post Helpful? 0
  • +
  • -

#7 MarmiteX1  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 159
  • Joined: 17-October 09

Re: Checking newer Zip file

Posted 13 January 2011 - 06:40 AM

View Postmodi123_1, on 22 December 2010 - 08:09 AM, said:

You need to add the appropriate breaks between the dd, mm, and yyyy. Something like "dd/mm/yyyy" or "dd-mm-yyyy".


Thanks its working.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1