Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 04:26:31 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Program that searches numbers inside a txt and perfroms following opperations  (Read 4024 times)

alogoc

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 19
    • View Profile
    • Donate to Member
So the whole idea is about a program that will search inside the txt,which I will give,every number that starts with _ (Example : _10165,_09957 ),and with the results it will search the directory which i give.Example C:\Id Boxes and tell me which of the numbers that searched from the txt are not found in this folder as archives (other .txts).Then cut those that found and ask me to create a folder with them.

I have attached a copy of how exactly the txt looks.In this txt there are the numbers that the program will "see" and perfrom the operations i said before.

The txt as you will see is in lines,every line has a number that starts with _(5 numbers follow).That number is an archive (a .txt) in another directory.What i want,is to search in that directory and find those archives.Then move them to folder wich i will name.It's imporant to tell me wich archives are not found...

I am very new to programming world,with no experience.
Some guy in another place posted me this code but it gets me build error,and not sure if fixed will do the job i want to do  :(

#include <sstream>
#include <fstream>
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    ifstream from(argv[1]);
    string line;
    int summa(0);
    while(getline(from, line))
    {
        stringstream str;
        str << line;
        int newValue(0);
        str >> newValue;
        summa += newValue;
    }
    cout << summa << "\n";
    return 0;
}

I've been searching this for long,but...nothing yet.
Any post,idea would be much appreciated.

Thanks for spending time reading my post
alogoc



« Last Edit: May 19, 2009, 09:02:46 AM by alogoc »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
Just to clarify-

You want to have a program that takes an input file, i.e. "IM1905091047_1.txt", a source directory name, i.e. "C:\Id Boxes" and a destination directory name, i.e. "C:\output".

With that information, you want the program to search in the source directory for .txt files that begin with numbers that start with "_" in the input file, i.e. for the file given, the program would search for "C:\Id Boxes\10165.txt", "C:\Id Boxes\09983.txt", "C:\Id Boxes\09983.txt", and "C:\Id Boxes\09957.txt".  The files that are found would be moved to "C:\output", and then a report of some kind would tell you if any of these files weren't found.

Is that correct?

A couple of questions
1. What about duplicate files?  In that scenario, there would be a duplicate of "C:\Id Boxes\09983.txt"  Of course you couldn't copy the file as is twice.  Would you want that in the report?

2. Would the "_" be included in the file name?  I assumed no in my example, but wanted to be sure.

alogoc

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 19
    • View Profile
    • Donate to Member
First of all,thanks for answering my question.

Well on the file :C\Id Boxes image that there are like 10 thousand files.Their names are like this : "IM1905091047_1_03521.txt"
And yes an output folder were the .txts will be moved.It would be nice if the program would create a folder,so i type the name,and move them in.
As you notice the whole scene is about to organise those 10 thousand .txts and put them into folders.

About the search in the C:\Id Boxes now.The "IM1905091047" except the IM,is day,month,year,time and minutes wich the txt was created,and it's named that way.Here is the reason why the program much search with the "_" in front:

Let's say in this case we want to search for 1047,there is this .txt right here "IM1905091047_1_03521" and this txt right here "IM1905091047_1_10231".
The search will bring both the archives,and we do not want that  :)

That's why there is the "_" there.The program will search for the _1047.Exaclty as it's reffered in the attached .txt i sent you.

About the report,yes!Definetly yes!Very nice idea of yours!There is good chance to be dublicate files there.
So we focus on the "_10231" part.The other part of the .txt name "IM1905091047_1" has nothing to do with us  :)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 8,406
  • "In my dreams, I always do it right."
    • View Profile
    • Donate to Member
If someone else gets to this first, feel free to take it; work has unexpectedly hit me with a lot to do.  Otherwise, I'll get to it as soon as I get a free moment.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,605
    • View Profile
    • Donate to Member
a bit more info on the output folders please - do you want all the matching files to go into a single directory, or do you want some sort of process where files are allocated to certain folders according to a predefined criteria?

alogoc

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 19
    • View Profile
    • Donate to Member
About the output,no,no process.Just move the matching files into a folder wich i will name into a different directory.That's it!
For any other details please ask me1

Thanks for answering my question
alogoC