Monday, October 10, 2011

Scanning pdf file in hard drive or folder source code in c++

This program use the batch processing.For batch processing we use Frofiles.exe command.
Syntax
FORFILES [/p Path] [/m Mask] [/s] [/c Command] [/d [+ | -] {dd/MM/yyyy | dd}]   

Parameter List:
    /P    pathname      Indicates the path to start searching.
                        The default folder is the current working directory (.).


    /M    searchmask    Searches files according to a searchmask. The default searchmask is '*' .

    /S                  Instructs forfiles to recurse into subdirectories. Like "DIR /S".

    /C    command       Indicates the command to execute for each file.
                        Command strings should be wrapped in double quotes.

                        The default command is "cmd /c echo @file".




                        The following variables can be used in the
                        command string:
                        @file    - returns the name of the file.
                        @fname   - returns the file name without extension.
                        @ext     - returns only the extension of the file.
                        @path    - returns the full path of the file.
                        @relpath - returns the relative path of the file.
                        @isdir   - returns "TRUE" if a file type is a directory, and "FALSE" for files.
                        @fsize   - returns the size of the file in bytes.
                        @fdate   - returns the last modified date of the file.
                        @ftime   - returns the last modified time of the file.

                        To include special characters in the command
                        line, use the hexadecimal code for the character
                        in 0xHH format (ex. 0x09 for tab). Internal
                        CMD.exe commands should be preceded with "cmd /c".




    /D    date          Selects files with a last modified date greater
                        than or equal to (+), or less than or equal to
                        (-), the specified date using the
                        "MM/dd/yyyy" format; or selects files with a
                        last modified date greater than or equal to (+)
                        the current date plus "dd" days, or less than or
                        equal to (-) the current date minus "dd" days. A
                        valid "dd" number of days can be any number in
                        the range of 0 - 32768.
                        "+" is taken as default sign if not specified.

    /?                  Displays this help message.

Examples:
    FORFILES /?
    FORFILES
    FORFILES /P C:\WINDOWS /S /M DNS*.*
    FORFILES /S /M *.txt /C "cmd /c type @file | more"
    FORFILES /P C:\ /S /M *.bat
    FORFILES /D -30 /M *.exe /C "cmd /c echo @path 0x09 was changed 30 days ago"
    FORFILES /D 01/01/2001 /C "cmd /c echo @fname is new since Jan 1st 2001"
    FORFILES /D +12/26/2008 /C "cmd /c echo @fname is new today"
    FORFILES /M *.exe /D +1
    FORFILES /S /M *.doc /C "cmd /c echo @fsize"
    FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"

If ForFiles finds one or more matches if will return %errorlevel% =0
If ForFiles finds no matches if will return %errorlevel% =1 and will print "ERROR: No files found with the specified search criteria."



Here is the source code copy and paste it and compile it in code::blocks.

#include <iostream>
#include <windows.h>
#include <string>
#include <dos.h>
 
// Read user input and use it in system() command//
int system(const char *command);
 
 
 
int main()
 
{
using namespace std;
char x;
char y;
char v;
 
system("color 1e");
 
cout << "\t\t!!!!WELCOME TO MR.ZAP'S PDF SCANNER!!!! \n\n\nHERE YOU CAN SCAN YOU HARD DISK FOR AVAILABLE .PDF FILES";
 
 
cout << "\n\nDO YOU WANT ME TO SCAN A DISK OR A SPECIFIC FOLDER. \n\nTYPE D for disk OR F for folder.:\n\n";
 
cin >> y;
 
if (y = 'd')
{
cout << "\n\nSPECIFY THE DISK YOU WANT TO SCAN AND HIT ENTER.: " << endl;
 
cin >> v;
 
string cmdLine = "forfiles.exe /p ";
cmdLine += v;
cmdLine += ":\\ /s /m *.pdf";
system(cmdLine.c_str());
}
else if (y = 'f')
{
cout << "\n\nSPECIFY THE FOLDER YOU WANT TO SCAN AND HIT ENTER.: " << endl;
 
cin >> x;
 
string cmdLine = "forfiles.exe /p ";
cmdLine += x;
cmdLine += ":\\ /s /m *.pdf";
system(cmdLine.c_str());
}
 
return 0;
 
}

2 comments: