Attemping to create a specialized file indexer (Moved from Beginner)

Hello, I am relatively new to programing, only took programming I and II so far, and I am attempting to create a program that gathers information on files in a folder, and it's subfolders, and prints said information to an html table.

The information it would extract is:

- The name of each file
- Where each file is located
- What purpose does the file serve
- If it's code, what other files does it reference


This would then be printed to an html table so that certain files are easier to find.

Thus far this is what I've written (just started),

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdlib>
#include <iostream>
#include <fstream> 

using namespace std;
using namespace System; 
using namespace System::IO; 

//Functions 

void openRoot (); 
void query (); 
void openSubDirs (); 
void queryFiles (); 

int createTable ();  

/// Vars 

int filesLeft; 
int filesRemaining; 

int main(int argc, char *argv[])
{
   ofstream navigate; 
   char getDir; 
   
   
   void openRoot () {
        
            
        cout << "Please enter a root directory to index ... " << endl << endl; 
        cin >> getDir; 
        
        navigate.open(getDir); 
        
        if (getDir == NULL) 
        {
           while (bool goBack == true)
           {
               cerr << "Please enter a valid directory ..." << endl; 
               cin >> getDir; 
               
               if(getDir == false) 
               {
                    bool goBack == true; 
                }
               else  
               {
                    bool goBack == false;
                }
            }
        }
        else
        {
            void query ()
            {
                cout << "Searching for files and subdirectories ... " << endl << endl << endl; 
                
                for (filesLeft > filesTotal; filesLeft++) 
                { 
                    void rootSize () 
                    {
                        try 
                        {
                            array <String^> dirs^ = Directory::Getfiles(getDir);
                            Console::WriteLine(dirs -> filesTotal); 
                            Collections::IEnumerator^ myEnum = dirs -> GetEnumorator(); 
                            
                            while (myEnum -> MoveNext() )
                            {
                                Console::WriteLine( myEnum -> Current ); 
                            }
                        }
                        catch ( Exception^ getDir) 
                        {
                            cerr << "An excseption has occured ..." << endl; 
                        }
                    }
                }


Now, I understand that this is nothing great yet, but this is just to get something on paper so to speak. Anyway, any tips and clues of how I could accomplish this would be greatly appreciated. :)

P.S. This is not for a class, this is something I wanted to do for the office I'm interning at to make finding files on web servers easier to find and edit. I already started make such an index manually. However, this is my last week and I wont be able to finish it that way. I have also heard that this might be easier to do in python, but my experience is in C++ and I don't have time to learn it.


Last edited on
Some more progress ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 
#include <cstdlib>
#include <iostream>
#include <fstream> 

using namespace std;
using namespace System; 
using namespace System::IO; 

//Functions 

void openRoot (); 
void query (); 
void openSubDirs (); 
void queryFiles (); 

int createTable ()
{ 
    ofstream wroteFile(indexName, ".html"); 
    if (wroteFile.is_open())
    {
        wroteFile << "<html>" ;
        wroteFile << "<head>" ;
        wroteFile << "<title>" << indexName << "(Index) </title>"; 
        wroteFile << "</head>";
        wroteFile << "<body>"; 
        wroteFile << "<table>"; 
        wroteFile << "<th> <bold>" << indexName 
        << " Index. </bold>"; 
        wroteFile << "<italic> Press (CTRL-F) to search!</italic>"
        << "</th>"; 
        
        // Column One 
        wroteFile << "<td><h2>Resource: <h2></td>"; 
            
        while(filesLeft < filesTotal) 
        {
            wroteFile << "<tr>" << Resource << "</tr>"; 
            filesLeft++; 
        }
        
        // Column Two 
        wroteFile << "<td><h2>Purpose: <h2></td>"; 
            
        while(filesLeft < filesTotal) 
        {
            wroteFile << "<tr>" << Purpose << "</tr>"; 
            filesLeft++; 
        }
        
        // Column Three 
        wroteFile << "<td><h2>Points To ... <h2></td>"; 
            
        while(filesLeft < filesTotal) 
        {
            wroteFile << "<tr>" << Points << "</tr>"; 
            filesLeft++; 
        }
        
         // Column Four 
        wroteFile << "<td><h2>Location: <h2></td>"; 
            
        while(filesLeft < filesTotal) 
        {
            wroteFile << "<tr><italic>" << Location << "</tr></italic>"; 
            filesLeft++; 
        }
        
        wroteList << "</table>"; 
        wroteList << "</body>"; 
        wroteList << "</html>"; 
        
    return 0; 
}
        


/// Vars 

int filesLeft; 
int filesTotal; 

int main(int argc, char *argv[])
{
   ofstream navigate; 
   char getDir; 
   
   
   void openRoot () {
        
            
        cout << "Please enter a root directory to index ... " << endl << endl; 
        cin >> getDir; 
        
        navigate.open(getDir); 
        
        if (getDir == NULL) 
        {
           while (bool goBack == true)
           {
               cerr << "Please enter a valid directory ..." << endl; 
               cin >> getDir; 
               
               if(getDir == false) 
               {
                    bool goBack == true; 
                }
               else  
               {
                    bool goBack == false;
                }
            }
        }
        else
        {
            void query ()
            {
                cout << "Searching for files and subdirectories ... " << endl << endl << endl; 
                
                for (filesLeft > filesTotal; filesLeft++) 
                { 
                    void rootSize () 
                    {
                        try 
                        {
                            array <String^> dirs^ = Directory::Getfiles(getDir);
                            Console::WriteLine(dirs -> filesTotal); 
                            Collections::IEnumerator^ myEnum = dirs -> GetEnumorator(); 
                            
                            while (myEnum -> MoveNext() )
                            {
                                Console::WriteLine( myEnum -> Current ); 
                            }
                        }
                        catch ( Exception^ getDir) 
                        {
                            cerr << "An excseption has occured ..." << endl; 
                        }
                    }
                }
   







Last edited on
Any ideas? Did I post on the wrong thread? Sorry if I did I'm new here.
A few comments.

1. I would split your main function up.

(I assume the nest functions are a C++.CLR thing? It's not normal C++. But it would more readbale it if was a bit less nested.)

2. Use endl when you write your XML

HTML parsers don't care about line breaks, but it makes the file a lot easier for a human to check!

3. Is the variable getDir the right type??

4. Is this code OK?

1
2
3
4
5
6
7
8
               if(getDir == false) 
               {
                    bool goBack == true; 
                }
               else  
               {
                    bool goBack == false;
                }


5 ...

Does your program actually compile? A normal C++ file would be failing to compile due to undefined variables? And I can see at least one mismatched brace.

(It's better to compile often while you are learning. Don't code too much extra code between compiles.

Also, I tend to code the controls structures, check it compiles, and only then populate.)

Andy
Last edited on
closed account (DSLq5Di1)
C++/CLI is an ugly mutant child that only a mother could love.. if you are not glued to the idea of using it, I recommend jumping ship to native C++ or C#.
I totally agree!!

The only CLI specific code looks like the directory/file enumeration code

Consider using FindFirstFile/FindNextFile/FindClose instead

Andy
Topic archived. No new replies allowed.