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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:11:36+00:00 2026-05-24T10:11:36+00:00

So I am working on a C# program that takes in a set of

  • 0

So I am working on a C# program that takes in a set of delimited text files within a directory and parses out the info within the files (i.e. the file path, file name, associated keywords). And this is what a sample file looks like…

C:\Documents and Settings\workspace\Extracted Items\image2.jpeg;image0;keyword1, keyword2, keyword3, keyword4
C:\Documents and Settings\workspace\Extracted Items\image3.jpeg;image1;keyword1, keyword2, keyword3, keyword4
C:\Documents and Settings\workspace\Extracted Items\image4.jpeg;image2;keyword1, keyword2, keyword3, keyword4
C:\Documents and Settings\workspace\Extracted Items\image5.jpeg;image3;keyword1, keyword2, keyword3, keyword4

Well I was given some code by my partner that does this, but I need to be able to access the list variable, that is populated within one of the methods. This is the code:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp
{
    public class FileIO
    {
        private static Boolean isTextFile;
        private static Boolean debug;

        private static int semiColonLoc1, semiColonLoc2, dblQuoteLoc1;
        private static int lineLength, currentTagLength;
        private static int numImages;
        private static int numFiles;
        public static List<Image> lImageSet;

        /*
          ****************************************************
          ***** CHANGE THIS PATH TO YOUR PROPERTIES FILE *****
          ****************************************************
        */
        private static readonly string propertiesFileDir = "C:/Documents and Settings/properties.properties";

        public PropertyKeys getProperties(string propertiesFileDir, PropertyKeys aPropertyKeys)
        {
            string line;
            string directoryKey = "extractedInfoDirectory";
            string debugKey = "debug2";
            string directory;

            Boolean isDirectoryKey;
            Boolean isDebugKey;

            System.IO.StreamReader file = new System.IO.StreamReader(propertiesFileDir);

            while ((line = file.ReadLine()) != null)
            {

                isDirectoryKey = false;
                isDebugKey = false;

                //  If the current line is a certain length, checks the current line's key
                if (line.Length > debugKey.Length)
                {
                    isDebugKey = line.Substring(0, debugKey.Length).Equals(debugKey, StringComparison.Ordinal);

                    if (line.Length > directoryKey.Length)
                    {
                        isDirectoryKey = line.Substring(0, directoryKey.Length).Equals(directoryKey, StringComparison.Ordinal);
                    }
                }

                //  Checks if the current line's key is the extractedInfoDirectory
                if (isDirectoryKey)
                {
                    directory = line.Substring(directoryKey.Length + 1);
                    aPropertyKeys.setExtractedInfoDir(directory);
                }

                //  Checks if the current line's key is the debug2
                else if (isDebugKey)
                {
                    debug = Convert.ToBoolean(line.Substring(debugKey.Length + 1));
                    aPropertyKeys.setDebug(debug);
                }
            }

            return aPropertyKeys;
        }

        public void loadFile()
        {

            string line;
            string tempLine;
            string fileToRead;
            string fileRename;
            string imagePath, imageName, imageTags, currentTag;
            string extractedInfoDir;
            string extension;
            string textfile = "txt";
            string[] filePaths;

            PropertyKeys aPropertyKeys = new PropertyKeys();

            //  Finds extractedInfoDir and debug values
            aPropertyKeys = getProperties(propertiesFileDir, aPropertyKeys);
            extractedInfoDir = aPropertyKeys.getExtractedInfoDir();
            debug = aPropertyKeys.getDebug();

            //  Finds all files in the extracted info directory
            filePaths = Directory.GetFiles(extractedInfoDir);
            numFiles = filePaths.Length;

            //  For each file in the directory...
            for (int n = 0; n < numFiles; n++)
            {
                int k = filePaths[n].Length;

                // Finds extension for the current file
                extension = filePaths[n].Substring(k - 3);

                // Checks if the current file is .txt
                isTextFile = extension.Equals(textfile, StringComparison.Ordinal);

                // Only reads file if it is .txt
                if (isTextFile == true)
                {

                    fileToRead = filePaths[n];
                    Console.WriteLine(fileToRead);
                    System.IO.StreamReader file = new System.IO.StreamReader(fileToRead);

                    //  Reset variables and create a new lImageSet object
                    lImageSet = new List<Image>();

                    line = ""; tempLine = ""; imagePath = ""; imageName = ""; imageTags = ""; currentTag = "";
                    semiColonLoc1 = 0; semiColonLoc2 = 0; dblQuoteLoc1 = 0; lineLength = 0; currentTagLength = 0; numImages = 0;

                    while ((line = file.ReadLine()) != null)
                    {

                        //  Creates a new Image object
                        Image image = new Image();
                        numImages++;

                        lineLength = line.Length;

                        //  Finds the image path (first semicolon delimited field)
                        semiColonLoc1 = line.IndexOf(";");
                        imagePath = line.Substring(0, semiColonLoc1);
                        image.setPath(imagePath);

                        tempLine = line.Substring(semiColonLoc1 + 1);

                        //  Finds the image name (second semicolon delimited field)
                        semiColonLoc2 = tempLine.IndexOf(";");
                        imageName = tempLine.Substring(0, semiColonLoc2);
                        image.setName(imageName);

                        tempLine = tempLine.Substring(semiColonLoc2 + 1);

                        //  Finds the image tags (third semicolon delimited field)
                        imageTags = tempLine;

                        dblQuoteLoc1 = 0;

                        // Continues to gather tags until there are none left
                        while (dblQuoteLoc1 != -1)
                        {
                            dblQuoteLoc1 = imageTags.IndexOf("\"");
                            imageTags = imageTags.Substring(dblQuoteLoc1 + 1);
                            dblQuoteLoc1 = imageTags.IndexOf("\"");

                            if (dblQuoteLoc1 != -1)
                            {
                                //  Finds the next image tag (double quote deliminated)
                                currentTag = imageTags.Substring(0, dblQuoteLoc1);
                                currentTagLength = currentTag.Length;

                                //  Adds the tag to the current image
                                image.addTag(currentTag);
                                image.iNumTags++;
                                imageTags = imageTags.Substring(dblQuoteLoc1 + 1);
                            }
                        }

                        //  Adds the image to the current image set
                        lImageSet.Add(image);

                    }

                    //  Prints out information about what information has been stored
                    if (debug == true)
                    {
                        Console.WriteLine("Finished file " + (n + 1) + ": " + filePaths[n]);

                        for (int i = 0; i < numImages; i++)
                        {
                            Console.WriteLine();
                            Console.WriteLine("***Image " + (i + 1) + "***");
                            Console.WriteLine("Name: " + lImageSet.ElementAt(i).getName());
                            Console.WriteLine("Path: " + lImageSet.ElementAt(i).getPath());
                            Console.WriteLine("Tags: ");

                            for (int j = 0; j < lImageSet.ElementAt(i).iNumTags; j++)
                            {
                                Console.WriteLine(lImageSet.ElementAt(i).lTags.ElementAt(j));
                            }

                        }
                    }

                    file.Close();

                    //  Changes destination file extension to .tmp
                    fileRename = fileToRead.Substring(0, fileToRead.Length - 4);
                    fileRename += ".tmp";

                    //  Changes file extension to .tmp
                    System.IO.File.Move(fileToRead, fileRename);
                }

                //  Not a text file
                else
                {
                    Console.WriteLine("Skipping file (no .txt extension)");
                }
            }
            Console.ReadLine();
        }
    }
}

However, I don’t want to mess with his code too much as he is not here for the time being to fix anything. So I just want to know how to access lImageSet from within his code in another class of mine. I was hoping it would be something like instantiating FileIO with FileIO fo = new FileIO, then doing something like fo.loadFile().lImageSet but that’s not the case. Any ideas?

  • 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-24T10:11:37+00:00Added an answer on May 24, 2026 at 10:11 am

    It’s public — so from your class, you can just access it as:

    FileIO.lImageSet
    

    To get to the values in it, just iterate over it as:

    //from FishBasketGordo's answer - load up the fo object
    FileIO fo = new FileIO();
    fo.loadFile();
    
    foreach(var img in FileIO.lImageSet) {
      //do something with each img item in lImageSet here...
    }
    

    EDIT: I built upon FishBasketGordo’s answer by incorporating his loadFile() call into my sample.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a cluster analysis program that takes a set of points S
I'm working on a program for class that takes in a number from 0
I'm working on a program that searches entire drives for a given file. At
I am working on a program that encodes a file based on a supplied
I'm working on a program that will sort files based on extension I currently
I am working with a simple command line application that takes in ASCI text
I'm trying to make a program that takes in one argument, a file, and
I'm working on an encryption application that for now encrypts text-only files. I need
I'm working on a python program that will automatically combine sets of files based
Hi so I'm working on a program that is designed to take a set

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.