how difficult would this be to do?

General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
Post Reply
User avatar
Faust
Posts: 8730
Joined: Sat Apr 22, 2000 4:34 am
Location: Huntington Beach, CA

how difficult would this be to do?

Post by Faust »

bear in mind i am not a coder.... well, i write code for CNC machines, but i mean as far as desktop programming.



what i am curious of, is would it be majorly difficult and/or expensive to have a program written to do the following......


take an existant .dat file (actually a Mazatrol CNC file, but it can be opened and modified in notepad), retrieve the date the file was last modified from Windows file properties, and insert that data in a pre-created .txt template (incorporating fields from the template) and copy the finished template in say... the first line, or (even better) the 10th line line of text of the .dat file..... then take the modified .dat file, leave the original where it was (unmodified) and make a copy in a predetermined directory in .txt format.


the reason i ask this is, in order to have 100% compliance to our procedural guidelines, all of our CNC program files have to have this data (copied as a text file) as a form of tracking (date created and modified and the like). it;s all part of ISO 9000 certification. and the problem is, we have literally THOUSANDS of program files, all of which never had this data entered. so, it may wind up being my responsability to manually do what i outlined above (which would take a long time, and probably drive me crazy in the process).


any help would be greatly appreciated.

thanks in advance.
"Today is a black day in the history of mankind."

- Leo Szilard
User avatar
parse27
Regular Member
Posts: 157
Joined: Thu Jun 20, 2002 1:34 pm
Location: 10,000 dreams and climbing

Post by parse27 »

its possible..

its wouldn't be that hard i guess and it wouldn't be expensive too. you could open the .dat file in as binary and access it, retrieve what you need, place the data where it should go and do the rest of the operations you described..
skipping sunbeams :)
User avatar
in2deep
Regular Member
Posts: 450
Joined: Mon Jul 14, 2003 11:49 am
Location: Denmark

Post by in2deep »

For any one particular file, this is very basic. However, you say you want to process many files, are these files all in the same directory? Are they named in such a way that a program will be able to identify them?

Your specification needs to be fleshed out a bit more.
User avatar
Faust
Posts: 8730
Joined: Sat Apr 22, 2000 4:34 am
Location: Huntington Beach, CA

Post by Faust »

sorry for the delay in response....


there are many files (thousands in total) in a bunch (dozens) of directories..... the program user's function would be to just select a group of files for execution of the batch process, with an output .txt file for each .dat processed.


should go like this:

- take .dat file and open as a .txt format in Notepad.

- access and copy the file property data through Windows (pretty much just the original "modified" date and time of the CNC program, or .dat in this case).

- copy this data in a predetermined format (really simple.. time and date created, original author name which will always be the case, etc... the only data that will be different is the original time/date of creation taken from windows file properties).

- insert that filled out "template" if you will onto line 10 of the .dat file (being read as a text document), and then save it as a .txt with the same original file name in a predetermined directory (will always be the same).
"Today is a black day in the history of mankind."

- Leo Szilard
User avatar
in2deep
Regular Member
Posts: 450
Joined: Mon Jul 14, 2003 11:49 am
Location: Denmark

Post by in2deep »

The original file...

sdkhfa hdkjf ahkj
sa djflkas dflkj
ldsa fjajsdfaj
sdjafl ajfl
sldjfalj
sldjf lasjdalgj
asldj la sjdflaj
aæsdæadfælakæ
asdf jaljfdjfla
sdfja lsjflkasjdfkl
jkl fd ljlf
fg
ljlf gjlsdjl
lfglajal jg
The end!

... and after processing...

sdkhfa hdkjf ahkj
sa djflkas dflkj
ldsa fjajsdfaj
sdjafl ajfl
sldjfalj
sldjf lasjdalgj
asldj la sjdflaj
aæsdæadfælakæ
asdf jaljfdjfla
Last changed 04/10/2003 14:44:30 by Bilbo Baggins
sdfja lsjflkasjdfkl
jkl fd ljlf
fg
ljlf gjlsdjl
lfglajal jg
The end!

The program I've just written searches for all the .dat files in a given directory, processes them in the manner shown and outputs the new .txt file to the same directory.

Code: Select all

#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;

class WORKPACKET
{
public:
    char DirPath[256];
    WIN32_FIND_DATA FindData;
};

void ProcessFile(WORKPACKET);

int main()
{
    WORKPACKET WorkPacket;
    char SearchPath[256];
    HANDLE hFind;
    int ErrorCode;
    BOOL Continue = TRUE;

    cout << "Enter directory to search..." << endl;
    cout << "EG C:\\Bobs\\Files" << endl << endl;
    cout << ">>> ";
    cin.getline(WorkPacket.DirPath, 255);
    strcpy(SearchPath, WorkPacket.DirPath);
    strcat(SearchPath, "\\*.dat");

    hFind = FindFirstFile(SearchPath,
                          &WorkPacket.FindData);

    if(hFind == INVALID_HANDLE_VALUE)
    {
        ErrorCode = GetLastError();
        if (ErrorCode == ERROR_FILE_NOT_FOUND)
        {
            cout << "There are no files matching that path/mask\n" << endl;
        }
        else if (ErrorCode == ERROR_PATH_NOT_FOUND)
        {
            cout << "The specified path is invalid\n" << endl;
        }
        else
        {
            cout << "FindFirstFile() returned error code " << ErrorCode << endl;
        }
        Continue = FALSE;
    }
    else
    {
        ProcessFile(WorkPacket);
    }

    if (Continue)
    {
        while (FindNextFile(hFind, &WorkPacket.FindData))
        {
            ProcessFile(WorkPacket);
        }

        ErrorCode = GetLastError();

        if (ErrorCode == ERROR_NO_MORE_FILES)
        {
            cout << endl << "All files processed." << endl;
        }
        else
        {
            cout << "FindNextFile() returned error code " << ErrorCode << endl;
        }

        if (!FindClose(hFind))
        {
            ErrorCode = GetLastError();
            cout << "FindClose() returned error code " << ErrorCode << endl;
        }
    }

    return 0;
}

void ProcessFile(WORKPACKET WorkPacket)
{
    ifstream InFile;
    ofstream OutFile;
    char FullPath1[256];
    char FullPath2[256];
    char FileLine[256];
    int i;
    SYSTEMTIME SysTime;

    strcpy(FullPath1, WorkPacket.DirPath);
    strcat(FullPath1, "\\");
    strcat(FullPath1, WorkPacket.FindData.cFileName);

    InFile.open(FullPath1);
    if (!InFile)
    {
        cout << "Program was unable to open file..." << endl;
        cout << WorkPacket.FindData.cFileName << endl;
    }
    else
    {
        strcpy(FullPath2, FullPath1);
        FullPath2[strlen(FullPath2) - 3] = NULL;
        strcat(FullPath2, "txt");

        OutFile.open(FullPath2);
        if (!OutFile)
        {
            cout << "Program was unable to create .txt file..." << endl;
            cout << WorkPacket.FindData.cFileName << endl;
        }
        else
        {
            for (i=0; i<9; i++)
            {
                InFile.getline(FileLine, 255);
                OutFile << FileLine << endl;
            }

            FileTimeToSystemTime(&WorkPacket.FindData.ftLastWriteTime, &SysTime);

            OutFile << "Last changed ";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wDay << "/";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wMonth << "/";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wYear << " ";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wHour << ":";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wMinute << ":";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wSecond;
            OutFile << " by Bilbo Baggins" << endl;

            while (!InFile.eof())
            {
                InFile.getline(FileLine, 255);
                OutFile << FileLine << endl;
            }

            cout << "Processed file..." << endl;
            cout << WorkPacket.FindData.cFileName << endl;
        }

    }

    return;
}
It makes a few assumptions, particulaly about the length of your pathnames and the line lengths in the files, and it assumes there are always AT LEAST 9 lines in the .dat file, and it's not very pretty - but I didn't want to spend more than an hour or so on it in case it was completely wrong! Compiles with MS VC++ but should work with pretty much anything.

Let me know how you get on.
User avatar
Faust
Posts: 8730
Joined: Sat Apr 22, 2000 4:34 am
Location: Huntington Beach, CA

Post by Faust »

Originally posted by in2deep
The original file...

sdkhfa hdkjf ahkj
sa djflkas dflkj
ldsa fjajsdfaj
sdjafl ajfl
sldjfalj
sldjf lasjdalgj
asldj la sjdflaj
aæsdæadfælakæ
asdf jaljfdjfla
sdfja lsjflkasjdfkl
jkl fd ljlf
fg
ljlf gjlsdjl
lfglajal jg
The end!

... and after processing...

sdkhfa hdkjf ahkj
sa djflkas dflkj
ldsa fjajsdfaj
sdjafl ajfl
sldjfalj
sldjf lasjdalgj
asldj la sjdflaj
aæsdæadfælakæ
asdf jaljfdjfla
Last changed 04/10/2003 14:44:30 by Bilbo Baggins
sdfja lsjflkasjdfkl
jkl fd ljlf
fg
ljlf gjlsdjl
lfglajal jg
The end!

The program I've just written searches for all the .dat files in a given directory, processes them in the manner shown and outputs the new .txt file to the same directory.

Code: Select all

#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;

class WORKPACKET
{
public:
    char DirPath[256];
    WIN32_FIND_DATA FindData;
};

void ProcessFile(WORKPACKET);

int main()
{
    WORKPACKET WorkPacket;
    char SearchPath[256];
    HANDLE hFind;
    int ErrorCode;
    BOOL Continue = TRUE;

    cout << "Enter directory to search..." << endl;
    cout << "EG C:\\Bobs\\Files" << endl << endl;
    cout << ">>> ";
    cin.getline(WorkPacket.DirPath, 255);
    strcpy(SearchPath, WorkPacket.DirPath);
    strcat(SearchPath, "\\*.dat");

    hFind = FindFirstFile(SearchPath,
                          &WorkPacket.FindData);

    if(hFind == INVALID_HANDLE_VALUE)
    {
        ErrorCode = GetLastError();
        if (ErrorCode == ERROR_FILE_NOT_FOUND)
        {
            cout << "There are no files matching that path/mask\n" << endl;
        }
        else if (ErrorCode == ERROR_PATH_NOT_FOUND)
        {
            cout << "The specified path is invalid\n" << endl;
        }
        else
        {
            cout << "FindFirstFile() returned error code " << ErrorCode << endl;
        }
        Continue = FALSE;
    }
    else
    {
        ProcessFile(WorkPacket);
    }

    if (Continue)
    {
        while (FindNextFile(hFind, &WorkPacket.FindData))
        {
            ProcessFile(WorkPacket);
        }

        ErrorCode = GetLastError();

        if (ErrorCode == ERROR_NO_MORE_FILES)
        {
            cout << endl << "All files processed." << endl;
        }
        else
        {
            cout << "FindNextFile() returned error code " << ErrorCode << endl;
        }

        if (!FindClose(hFind))
        {
            ErrorCode = GetLastError();
            cout << "FindClose() returned error code " << ErrorCode << endl;
        }
    }

    return 0;
}

void ProcessFile(WORKPACKET WorkPacket)
{
    ifstream InFile;
    ofstream OutFile;
    char FullPath1[256];
    char FullPath2[256];
    char FileLine[256];
    int i;
    SYSTEMTIME SysTime;

    strcpy(FullPath1, WorkPacket.DirPath);
    strcat(FullPath1, "\\");
    strcat(FullPath1, WorkPacket.FindData.cFileName);

    InFile.open(FullPath1);
    if (!InFile)
    {
        cout << "Program was unable to open file..." << endl;
        cout << WorkPacket.FindData.cFileName << endl;
    }
    else
    {
        strcpy(FullPath2, FullPath1);
        FullPath2[strlen(FullPath2) - 3] = NULL;
        strcat(FullPath2, "txt");

        OutFile.open(FullPath2);
        if (!OutFile)
        {
            cout << "Program was unable to create .txt file..." << endl;
            cout << WorkPacket.FindData.cFileName << endl;
        }
        else
        {
            for (i=0; i<9; i++)
            {
                InFile.getline(FileLine, 255);
                OutFile << FileLine << endl;
            }

            FileTimeToSystemTime(&WorkPacket.FindData.ftLastWriteTime, &SysTime);

            OutFile << "Last changed ";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wDay << "/";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wMonth << "/";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wYear << " ";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wHour << ":";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wMinute << ":";
            OutFile.width(2);
            OutFile.fill('0');
            OutFile << SysTime.wSecond;
            OutFile << " by Bilbo Baggins" << endl;

            while (!InFile.eof())
            {
                InFile.getline(FileLine, 255);
                OutFile << FileLine << endl;
            }

            cout << "Processed file..." << endl;
            cout << WorkPacket.FindData.cFileName << endl;
        }

    }

    return;
}
It makes a few assumptions, particulaly about the length of your pathnames and the line lengths in the files, and it assumes there are always AT LEAST 9 lines in the .dat file, and it's not very pretty - but I didn't want to spend more than an hour or so on it in case it was completely wrong! Compiles with MS VC++ but should work with pretty much anything.

Let me know how you get on. [/b]




wow! i was not expecting anyone to invest any time in this. but, if it's OK, i would like to gather all the specifics in detail (in terms of the exact wording and format and such), and also speak with our management to see if we can work something out monetarily-speaking for you if they decide to move forward with this.

i will only need one thing from you at this point....... could you give me a scope of how many hours it would take to create a finished product? it doesn;t have to be polished and pretty... just the data in the template form is what's important. file names will never be longer than 15 characters, and pathnames wouldn;t be longer than 3 to 5 subdirectories deep on the source drive (if thats what you mean by filepath length).

if you could please not invest any more time, i would be much more comfortable. though my recommendation to management may be sound (in my opinion), it;s ultimately their decision as to the who's and how's of how we will go about having this done.

i will contact you or post here one way or the other. thank you very much.
"Today is a black day in the history of mankind."

- Leo Szilard
User avatar
in2deep
Regular Member
Posts: 450
Joined: Mon Jul 14, 2003 11:49 am
Location: Denmark

Post by in2deep »

By a "finished product" do you mean simply a compiled executable with noddy user guide, (won't be more than a few lines - it really isn't that difficult!) if so, will not take long. The design and coding has been done. It is simply a case of tweaking up the formats now, (I didn't expect Bilbo Baggins to be your editor!).

Is the "before and after" what you actually wanted - sounded like it?

Get the formatting details to me asap - I won't do it yet if you wish, but I'd like to see it so I can see if there are any unexpected nasties waiting to bite!

Post or PM me, whatever.
User avatar
Faust
Posts: 8730
Joined: Sat Apr 22, 2000 4:34 am
Location: Huntington Beach, CA

Post by Faust »

Originally posted by in2deep
By a "finished product" do you mean simply a compiled executable with noddy user guide, (won't be more than a few lines - it really isn't that difficult!) if so, will not take long. The design and coding has been done. It is simply a case of tweaking up the formats now, (I didn't expect Bilbo Baggins to be your editor!).

Is the "before and after" what you actually wanted - sounded like it?

Get the formatting details to me asap - I won't do it yet if you wish, but I'd like to see it so I can see if there are any unexpected nasties waiting to bite!

Post or PM me, whatever.



well, this is kind of embarrassing, but i have no idea what to do with the code you posted, as far as making it function...... but, it does sound, by your description, like we are more or less on the same frequency. if you could give me a hint as to how to make the code work, i could make sure of that.

and, yes... by "finished product" i do mean an executable. the user will more than likely be me. not sure if a window with a field for the directory containing the files to be processed (drag/drop or whatever would be easiest to work with). not sure what would be the best compromise between ease of coding vs. easy of use. that can be worked out when the full set of details has been acquired. i will need to go to get all the details and check with management if this is something they would approve of. i would say by next weekend i will have all the necessary information.

so, in total, what kind of time investment are we looking at? i am not looking for a fixed number, but are we talking say....... 5 to 10 hours or billable work? 10 to 20? i just need a general apprioximation to take to management (that's how they primarily do business..... how many hours it will take to make something).

and again, i would like you to not spend any more time on this, as i cannot guarantee it will get approval... and i would feel really bad if they decide to go with a local company or whatever, and you have already spent personal time on it.


thank you very much. i will be in contact one way or the other.
"Today is a black day in the history of mankind."

- Leo Szilard
User avatar
in2deep
Regular Member
Posts: 450
Joined: Mon Jul 14, 2003 11:49 am
Location: Denmark

Post by in2deep »

The code there is C++ source code. To make it work you'll need to compile it to form a .exe. If you have a compiler, this should take you no more than 5 minutes to load it up compile it and be running.

As it stands now, there is no GUI - the program runs in a Windows console, (a "DOS Box" - oooh, how I hate that term). It is something of a classic with programming for Windows, you want a simple app knocked together, takes a few hours in a console, you want a GUI on the top, now you start talking days.

It literally, puts a prompt on the screen which says...

Enter a directory to search...
EG C:\Bobs\Files
>>>

you type in the path, and it goes through all the .dat files in that directory creating the .txt files with the last updated date on line 10. It lists them to the screen as it does them, any errors encountered are also just written out to the screen.

It's a "get the job done" basically "one off disposable" program. Frankly, I couldn't stand the thought of some poor sod, (you possibly), being given the incredibly dull, boring and soul destroying task of manually editing 10's of thousand of files, day after day for weeks probably, when I could knock up an app to do it in a few hours.

I can't send you an .exe through the board. PM me your e-mail address and I'll send you a compiled .exe with some simple instructions. Run it on one of the directories where you have these .dat files, (actually, what I would recommend is you make a copy of such a directory so you can clean up easily after), the formats won't be right yet but trying it in the real environment will flag any as yet unforseen problems.

The program is European, so the date it puts in is DD/MM/YYYY - when specifying the eventual format - be precise over how the date should be formatted.

If you want me to estimate the work required to put a GUI on it, I'll need more info on what you had in mind - D and D can get fiddly depending on the controls used. Can you also confirm your Windows version when replying.

As it stands at the moment, there is about 2 hours work there.
User avatar
Faust
Posts: 8730
Joined: Sat Apr 22, 2000 4:34 am
Location: Huntington Beach, CA

Post by Faust »

i really appreciate the effort you have put forth so far. the only hitch is, i will have to run this by upper management.... and as of yet, i have no idea if they will approve of this or not. for all i know, they want to only do business with an established company for this (and likely add an extra zero on the end of the amount they will wind up paying), or maybe even just pay someone to do it manually (management can make seemingly silly decisions from time to time). they will probably incorporate many more variables than i am in considering what they want to do and how they want to do business.

i am not opposed to it being just a command window as compared to a GUI. just as long as the user is prompted for the needed input for each batch operation.

and as far as the "disposable program" idea, that's exactly what it will wind up being. we are currently in the process of having our CAM software source create a modification to the products of theirs that we own so that this data will be entered and saved upon CNC program creation.... ie, no future need for the app.


anyways, i will be in touch one way or the other. many thanks for your help so far.
"Today is a black day in the history of mankind."

- Leo Szilard
Post Reply