What's new

{REQUEST} Automatic Folder Scanner / Page Counter Program / Page Counting Script

  • Thread starter TheChosenSphinx
  • Start date
  • Views 2,281
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Okay so basically here is what is going on.

I have recently been working on a massive project on a vast scale. I mean this is all text and word based documents from OpenOffice.

I have 1 Main Folder, within that folder I have 12 sub-folders, within those 12 sub-folders I have various amounts of OpenOffice word documents in each sub-folder.

The documents are OpenDocument Text (.ODT), or ODT files.

I have well over 200 individual documents (all of them are .odt files) in the entire folder as stated by right clicking on the main folder and selecting properties.

I was able to find out I have 213 files in 12 different folders.

Now the problem is that it does not tell me how many pages (total number of pages) in the entire folder that I have to print.

I was wondering if there was a program or script out there (or if somebody with knowledge on programming and scripting) that could help me out with this project.


Even if you have to create a program from scratch, your programming knowledge will not go to waste.



Here is my idea:




Basically there has to be a script/program that can scan all the contents in the main folder, then scan the 12 sub-folders I have within the main folder.


Then the program could scan all of the ODT files in each of the sub-folders and count the number of pages that is in each of the odt document files.

Then give me a total number of pages for the entire project.



End of idea.

It would save me the hassle of clicking on each odt file and going to print preview just to see the number of pages I am going to be printing out.

Any help would be appreciated, so thanks a bunch in advance.
 
Last edited:
Xeren

Xeren

♦♦♦ God Complex ♦♦♦
Legendary Veteran Programmer Modder
Messages
5,668
Reaction score
2,107
Points
795
Sin$
0
EDIT: Don't quote such a large OP.

You'd have to get the maximum line count a page for the program, and then divide the number of lines a document has by that number to get the number of pages.
 
Last edited by a moderator:
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
You'd have to get the maximum line count a page for the program, and then divide the number of lines a document has by that number to get the number of pages.


You think you would be able to make a program for me. Like I said I just need a program that has the ability to:

1. Scan a folder.

2. Scan that folders sub-folders.

3. Scan and analyze each text documents / ODT files within those sub-folders.

4. Calculate the number of pages (Number of pages that it will print out with my printer) within those files and documents.

5. Display the total or sum of the calculation. (Display the number of pages that it will ultimately print out as the end result.



Would you know how to make a program like this, such as this or something similar? You do mention to PM you if I need a program created or built, so I am assuming you know how to program.

I understand that certain factors determine how many pages a text document will have, such as: Font, Font Size etc etc.
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Is ODT an extension because I have an app written for you and if it is then I need to add it to the code. Also, what font are you using because I have it set to 12 which is standard.
 
Last edited:
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Is ODT an extension because I have an app written for you and if it is then I need to add it to the code. Also, what font are you using because I have it set to 12 which is standard.

Yea, ODT is the file extension. It is an .ODT file extension. Basically it is just a simple text file, such as .rtf or .doc, but yes mine is .odt

Now the font size I am using is actually 20, the font is Times New Roman size 20.

So you already have a program that scans for the number of pages within text documents within a folder? Fantastic!! Your help will be much appreciated, and it won't go unnoticed.

What is the program written in?
 
Last edited:
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Yea, ODT is the file extension. It is an .ODT file extension. Basically it is just a simple text file, such as .rtf or .doc, but yes mine is .odt

Now the font size I am using is actually 20, the font is Times New Roman size 20.

So you already have a program that scans for the number of pages within text documents within a folder? Fantastic!! Your help will be much appreciated, and it won't go unnoticed.

What is the program written in?
It is written in C# because there is no need for an unmanaged language and how many lines are you fitting on a page at size 20?
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
It is written in C# because there is no need for an unmanaged language and how many lines are you fitting on a page at size 20?

Well now that's actually a little bit harder to calculate. I have an unorthodox style of typing and writing.

Sometimes I will finish a sentence and hit the enter-bar twice to give the next sentence some space from the other. I also use numbered lists as well, each number having a separate line, of course, ranging anywhere from ten to over 100 numbers per list.

So it really does vary, which is why I needed something of this sort to help me count the pages, because I will be taking my documents to a printing service and have them print it all out for me.

So it would be nice to give them the number of pages before they start, so I know how much it is generally going to cost.


UPDATE: I am also using 24 size font as headers at the beginning of an idea.

24 Font Size can fit 24 lines on one page, coincidentally.

20 Font Size can fit 29 line on one page.


Like I said though, the only time I use the 24 size of font is at the very beginning of the document, the rest of the document is in size 20 font.

Hope this helps out.
 
Last edited:
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
It is written in C# because there is no need for an unmanaged language and how many lines are you fitting on a page at size 20?

Okay so I just did an experimental test. I started out with size 24 font, pushed enter and then switched to size 20 font, then pushed enter until the new page appeared.

The result is that (with my typing style), I can fit exactly 29 Lines on One Page.

So I hope you use that information however you can, I appreciate your helping me out with this matter. So thanks.
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Okay so I just did an experimental test. I started out with size 24 font, pushed enter and then switched to size 20 font, then pushed enter until the new page appeared.

The result is that (with my typing style), I can fit exactly 29 Lines on One Page.

So I hope you use that information however you can, I appreciate your helping me out with this matter. So thanks.
Yes that thelps and the program is done BTW. Do you want the app and source or just the app?
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Both if you got them.....the program application definitely, and since I am trying to break into programming, the source would be nice to review as well.Thanks a bunch partner.
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Source:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
//Additional includes
using System.Windows.Forms;
using System.IO;
 
namespace _7S_App
{
    class Program
    {
        private static readonly string appPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\";
 
        static void Main(string[] args)
        {
            Console.Title = "ODT/Text File Counter";
 
            //Clear Log
            if (File.Exists(appPath + "debug.txt"))
            {
                File.Delete(appPath + "debug.txt");
            }
 
            writeLog("//Main Scan");
 
            string[] subFolders = Directory.GetDirectories(appPath);
            List<string> fileList = new List<string>();
            foreach (string sub in subFolders)
            {
                writeLog("Scanning -> " + sub);
                string[] subFiles = getFiles(sub, "*.txt|*.odt");
                foreach (string file in subFiles)
                {
                    fileList.Add(file);
                    if (Path.GetExtension(file) == ".txt")
                    {
                        writeLog("Text File Found at -> " + file);
                    }
                    if (Path.GetExtension(file) == ".odt")
                    {
                        writeLog("ODT File Found at -> " + file);
                    }
                }
            }
 
            writeLog(Environment.NewLine + "//Line Counts");
 
            string[] txtLocs = fileList.ToArray();
            List<int> totLines = new List<int>();
            foreach (string txtParse in txtLocs)
            {
                int count = lineCount(txtParse);
                writeLog("Line count in file -> " + txtParse + " -> " + count);
                totLines.Add(count);
            }
 
            int total = 0;
            for (int x = 0; x < totLines.ToArray().Length; x++)
            {
                total = total + totLines[x];
            }
 
            writeLog(Environment.NewLine + "//Results");
 
            decimal mathInt = Decimal.Divide(total, (int)FontSize.Twenty); //For 24/20 font <- Standard
            decimal totalPages = Math.Round(mathInt, 2);
 
            Console.WriteLine("Total Lines in Subfolders' Text Documents: " + total);
            writeLog("Total Lines in Subfolders' Text Documents: " + total);
            Console.WriteLine("Total Pages to Print @12 Font: " + totalPages);
            writeLog("Total Pages to Print @24/20 Font: " + totalPages);
 
 
            //Wait for user input
            Console.WriteLine("Press any key to exit application...");
            Console.ReadKey();
        }
 
        private enum FontSize : int
        {
            Twenty = 29,
            Twelve = 46,
        }
 
        private static string[] getFiles(string sourceFolder, string filters)
        {
            return filters.Split('|').SelectMany(filter => Directory.GetFiles(sourceFolder, filter)).ToArray();
        }
 
        private static int lineCount(string filename)
        {
            int count = 0;
            using (StreamReader r = new StreamReader(filename))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    count++;
                }
            }
            return count;
        }
 
        private static void writeLog(string text, string logFile = "debug.txt")
        {
            if (!File.Exists(appPath + logFile))
            {
                File.WriteAllText(appPath + logFile, text + Environment.NewLine);
            }
            else
            {
                File.AppendAllText(appPath + logFile, text + Environment.NewLine);
            }
        }
    }
}
Download:

You need to put that application in the root folder that you want to scan and it requires .NET framework 4.5. Also, as far as code goes, I could have probably made it more simple and just used SearchOption.AllDirectories and that would have handled it.
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Source:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
//Additional includes
using System.Windows.Forms;
using System.IO;
 
namespace _7S_App
{
    class Program
    {
        private static readonly string appPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\";
 
        static void Main(string[] args)
        {
            Console.Title = "ODT/Text File Counter";
 
            //Clear Log
            if (File.Exists(appPath + "debug.txt"))
            {
                File.Delete(appPath + "debug.txt");
            }
 
            writeLog("//Main Scan");
 
            string[] subFolders = Directory.GetDirectories(appPath);
            List<string> fileList = new List<string>();
            foreach (string sub in subFolders)
            {
                writeLog("Scanning -> " + sub);
                string[] subFiles = getFiles(sub, "*.txt|*.odt");
                foreach (string file in subFiles)
                {
                    fileList.Add(file);
                    if (Path.GetExtension(file) == ".txt")
                    {
                        writeLog("Text File Found at -> " + file);
                    }
                    if (Path.GetExtension(file) == ".odt")
                    {
                        writeLog("ODT File Found at -> " + file);
                    }
                }
            }
 
            writeLog(Environment.NewLine + "//Line Counts");
 
            string[] txtLocs = fileList.ToArray();
            List<int> totLines = new List<int>();
            foreach (string txtParse in txtLocs)
            {
                int count = lineCount(txtParse);
                writeLog("Line count in file -> " + txtParse + " -> " + count);
                totLines.Add(count);
            }
 
            int total = 0;
            for (int x = 0; x < totLines.ToArray().Length; x++)
            {
                total = total + totLines[x];
            }
 
            writeLog(Environment.NewLine + "//Results");
 
            decimal mathInt = Decimal.Divide(total, (int)FontSize.Twenty); //For 24/20 font <- Standard
            decimal totalPages = Math.Round(mathInt, 2);
 
            Console.WriteLine("Total Lines in Subfolders' Text Documents: " + total);
            writeLog("Total Lines in Subfolders' Text Documents: " + total);
            Console.WriteLine("Total Pages to Print @12 Font: " + totalPages);
            writeLog("Total Pages to Print @24/20 Font: " + totalPages);
 
 
            //Wait for user input
            Console.WriteLine("Press any key to exit application...");
            Console.ReadKey();
        }
 
        private enum FontSize : int
        {
            Twenty = 29,
            Twelve = 46,
        }
 
        private static string[] getFiles(string sourceFolder, string filters)
        {
            return filters.Split('|').SelectMany(filter => Directory.GetFiles(sourceFolder, filter)).ToArray();
        }
 
        private static int lineCount(string filename)
        {
            int count = 0;
            using (StreamReader r = new StreamReader(filename))
            {
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    count++;
                }
            }
            return count;
        }
 
        private static void writeLog(string text, string logFile = "debug.txt")
        {
            if (!File.Exists(appPath + logFile))
            {
                File.WriteAllText(appPath + logFile, text + Environment.NewLine);
            }
            else
            {
                File.AppendAllText(appPath + logFile, text + Environment.NewLine);
            }
        }
    }
}
Download:

You need to put that application in the root folder that you want to scan and it requires .NET framework 4.5.






Okay so this is a RAR file, I put it into the folder that I want to scan. Now how do I use the program, it says I cannot open the RAR file because I do not have the right program to open the RAR file extension.

What exactly do I need to open it, I mean I have 7-zip, which is very similar to WinZip?
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Okay so this is a RAR file, I put it into the folder that I want to scan. Now how do I use the program, it says I cannot open the RAR file because I do not have the right program to open the RAR file extension.

What exactly do I need to open it, I mean I have 7-zip, which is very similar to WinZip?
WinRar
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Ok, So do I put the RAR file in the root folder needing to be scanned, or the actual application within the RAR file in the root folder.

Still trying to figure out how to use this program, I'm sure it works, just need help executing the program.
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Ok, So do I put the RAR file in the root folder needing to be scanned, or the actual application within the RAR file in the root folder.

Still trying to figure out how to use this program, I'm sure it works, just need help executing the program.
Put the exe file in the root folder to be scanned.
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Thanks a bunch, I got it working now. I appreciate the help.

At the end of the scan it says: "Total pages to print @12 font"?

I was wondering if this is supposed to be changed to 20 font? Just wondering?
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
Thanks a bunch, I got it working now. I appreciate the help.

At the end of the scan it says: "Total pages to print @12 font"?

I was wondering if this is supposed to be changed to 20 font? Just wondering?
I just updated that it has the same download link.
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
Fantastic, just fantastic. Thank you so much...This is a much needed program out there, not sure why no mainstream developed has anything like this out there yet...

But this works perfect, no complaints with it. I am downloading the updated version now.
 
TheChosenSphinx

TheChosenSphinx

Enthusiast
Messages
166
Reaction score
2
Points
70
Sin$
0
I just updated that it has the same download link.

You certainly know your way around C Sharp, this program really is incredible. I can see me using this for a lot of my projects that require multi-tiered folders and file documents.
 
Visual Studio

Visual Studio

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
You certainly know your way around C Sharp, this program really is incredible. I can see me using this for a lot of my projects that require multi-tiered folders and file documents.
Indeed I do :wink: and if you haven't already noticed it prints out a debug.txt file.
 
Top Bottom
Login
Register