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 514199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:29:59+00:00 2026-05-13T07:29:59+00:00

I’m trying to write a simple program that will compare the files in separate

  • 0

I’m trying to write a simple program that will compare the files in separate folders. I’m currently using LINQ to Objects to parse the folder and would like to included information extracted from the string in my result set as well.

Here’s what I have so far:

FileInfo[] fileList = new DirectoryInfo(@"G:\Norton Backups").GetFiles();

var results = from file in fileList
              orderby file.CreationTime
              select new { file.Name, file.CreationTime, file.Length };

foreach (var x in results)
    Console.WriteLine(x.Name);

This produces:

AWS025.sv2i
AWS025_C_Drive038.v2i
AWS025_C_Drive038_i001.iv2i
AWS025_C_Drive038_i002.iv2i
AWS025_C_Drive038_i003.iv2i
AWS025_C_Drive038_i004.iv2i
AWS025_C_Drive038_i005.iv2i    
...

I would like to modify the LINQ query so that:

  • It only includes actual “backup” files (you can tell the backup files because of the _C_Drive038 in the examples above, though 038 and possibly the drive letter could change).
  • I want to include a field if the file is the “main” backup file (i.e., it doesn’t have _i0XX at the end of the file name).
  • I want to include the “image number” of the file (e.g. in this case it’s 038).
  • I want to include the increment number if it’s an incrememnt of a base file (e.g. 001 would be an increment number)

I believe the basic layout of the query would look like the following, but I’m not sure how best to complete it (I’ve got some ideas for how some of this might be done, but I’m interested to heard how others might do it):

var results = from file in fileList
              let IsMainBackup = \\ ??
              let ImageNumber = \\ ??
              let IncrementNumber = \\ ??
              where \\ it is a backup file.
              orderby file.CreationTime
              select new { file.Name, file.CreationTime, file.Length, 
                           IsMainBackup, ImageNumber, IncrementNumber };

When looking for the ImageNumber and IncrementNumber, I would like to assume that the location of this data is not always fixed, meaning, I’d like to know of a good way to parse this (If this requires RegEx, please explain how I might use it).

NOTE: Most of my past experience in parsing text involved using location-based string functions, such as LEFT, RIGHT, or MID. I’d rather not fall back on those if there is a better way.

  • 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-05-13T07:30:00+00:00Added an answer on May 13, 2026 at 7:30 am

    Using regular expressions:

        Regex regex = new Regex(@"^.*(?<Backup>_\w_Drive(?<ImageNumber>\d+)(?<Increment>_i(?<IncrementNumber>\d+))?)\.[^.]+$");
        var results = from file in fileList
                      let match = regex.Match(file.Name)
                      let IsMainBackup = !match.Groups["Increment"].Success
                      let ImageNumber = match.Groups["ImageNumber"].Value
                      let IncrementNumber = match.Groups["IncrementNumber"].Value
                      where match.Groups["Backup"].Success
                      orderby file.CreationTime
                      select new { file.Name, file.CreationTime, file.Length,
                                   IsMainBackup, ImageNumber, IncrementNumber };
    

    Here is a description of the regular expression:

    ^                   Start of string.
    .*                  Allow anything at the start.
    (?<Backup>...)      Match a backup description (explained below).
    \.                  Match a literal period.
    [^.]+$              Match the extension (anything except periods).
    $                   End of string.
    

    Backup is:

    _\w_Drive           A literal underscore, any letter, another underscore, then the string "Drive".
    (?<ImageNumber>\d+) At least one digit, saved as ImageNumber.
    (?<Increment>...)?  An optional increment description.
    

    Increment is:

    _i                      A literal underscore, then the letter i.
    (?<IncrementNumber>\d+) At least one digit, saved as IncrementNumber.
    

    Here is the test code I used:

    using System;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Linq;
    
    class Program
    {
        static void Main(string[] args)
        {
            FileInfo[] fileList = new FileInfo[] {
                new FileInfo("AWS025.sv2i"),
                new FileInfo("AWS025_C_Drive038.v2i"),
                new FileInfo("AWS025_C_Drive038_i001.iv2i"),
                new FileInfo("AWS025_C_Drive038_i002.iv2i"),
                new FileInfo("AWS025_C_Drive038_i003.iv2i"),
                new FileInfo("AWS025_C_Drive038_i004.iv2i"),
                new FileInfo("AWS025_C_Drive038_i005.iv2i")
            };
    
            Regex regex = new Regex(@"^.*(?<Backup>_\w_Drive(?<ImageNumber>\d+)(?<Increment>_i(?<IncrementNumber>\d+))?)\.[^.]+$");
            var results = from file in fileList
                          let match = regex.Match(file.Name)
                          let IsMainBackup = !match.Groups["Increment"].Success
                          let ImageNumber = match.Groups["ImageNumber"].Value
                          let IncrementNumber = match.Groups["IncrementNumber"].Value
                          where match.Groups["Backup"].Success
                          orderby file.CreationTime
                          select new { file.Name, file.CreationTime,
                                       IsMainBackup, ImageNumber, IncrementNumber };
    
            foreach (var x in results)
            {
                Console.WriteLine("Name: {0}, Main: {1}, Image: {2}, Increment: {3}",
                    x.Name, x.IsMainBackup, x.ImageNumber, x.IncrementNumber);
            }
        }
    }
    

    And here is the output I get:

    Name: AWS025_C_Drive038.v2i, Main: True, Image: 038, Increment:
    Name: AWS025_C_Drive038_i001.iv2i, Main: False, Image: 038, Increment: 001
    Name: AWS025_C_Drive038_i002.iv2i, Main: False, Image: 038, Increment: 002
    Name: AWS025_C_Drive038_i003.iv2i, Main: False, Image: 038, Increment: 003
    Name: AWS025_C_Drive038_i004.iv2i, Main: False, Image: 038, Increment: 004
    Name: AWS025_C_Drive038_i005.iv2i, Main: False, Image: 038, Increment: 005
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 354k
  • Answers 354k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer do { stuff() } while(0); is doing the exact same… May 14, 2026 at 8:25 am
  • Editorial Team
    Editorial Team added an answer You're thinking of the button instance in terms of the… May 14, 2026 at 8:25 am
  • Editorial Team
    Editorial Team added an answer After some math I managed to work it out. Later… May 14, 2026 at 8:25 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.