+-------------------- FILEEXPORTER: COPYRIGHT NOTICE --------------------+
|                   Copyright (C) Ezra Kenigsberg 2012                   |
| Permission is hereby granted, free of charge, to any person obtaining  |
| a copy of this software and associated documentation files (the        |
| "Software"), to deal in the Software without restriction, including    |
| without limitation the rights to use, copy, modify, merge, publish,    |
| distribute, sublicense, and/or sell copies of the Software, and to     |
| permit persons to whom the Software is furnished to do so, subject to  |
| the following conditions:                                              |
|                                                                        |
| The above copyright notice and this permission notice shall be         |
| included in all copies or substantial portions of the Software.        |
|                                                                        |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        |
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     |
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   |
| CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   |
| TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      |
| SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 |
+------------------------------------------------------------------------+

REQUIREMENTS
1) Windows XP (or above)
2) A Salesforce login with API access
3) Apex Data Loader 17 (download the installer from
   http://bit.ly/apexdataloaders)

HOW TO USE FILEEXPORTER
1) Download the zipfile from http://bit.ly/fileexporter
2) Unzip all files from the FileExporter zipfile to a folder on your
   hard drive.
3) Double-click +FileExporter.bat.
4) Respond to onscreen prompts.  Some options are shown in parentheses; do 
   not type parentheses when providing your responses.

FREQUENTLY-ASKED QUESTIONS
Q: "How does FileExporter work?"
A: FileExporter is a command-line utility (ie, a program in a text window) 
   that automates Data Loader.  Neither Salesforce nor Data Loader needs to 
   be open on your PC when you run FileExporter.  Once run, FileExporter 
   will need to know responses to several questions displayed in the text
   window, including username, password, and security token (if required).

Q: "Does FileExporter work with Data Loader version [X]?"
A: FileExporter works best with Data Loader version 17. It won't work at
   all with any version after 23. Download installers for Data Loader here:
   http://bit.ly/apexdataloaders
   
Q: "When I run FileExporter, it says 'The system cannot find the path 
   specified.' What does that mean?"
A: FileExporter needs to be told where Data Loader is installed on your PC.
   By default, it assumes "C:\Program Files\salesforce.com\Apex Data 
   Loader 17.0". FileExporter's default path can also be customized by 
   editing the fourth line of the "+FileExporter.bat" file in Notepad.

Q: "How can I tell if FileExporter is working properly?"
A: FileExporter writes detailed status messages to a file called "log.txt".
   That file is automatically deleted when you quit FileExporter, but you can 
   override that behavior by editing the fifth line of the "+FileExporter.bat"
   file in Notepad (change "SET SaveLog=n" to "SET SaveLog=y"). 

Q: "How do I get FileExporter to download Files?"
A: The documents stored in Salesforce's Files tab are a kind of Content, and 
   will be downloaded when you use FileExporter to download Content.
   
Q: "My downloaded Attachments/Content/Documents are empty! What's wrong?"
A: Lately people have been getting heap errors. I've implemented fixes
   (thanks to Sanket Deshmukh and Michael Fitzgerald!) that should help 
   MOST of the time. Download and use the latest version. If you're still
   getting zero-byte extracted CSVs or empty Attachments/Content/Documents, 
   try one of the following two  procedures:
   A) export a smaller group of Attachments/Content/Documents; see the last
      Q&A, "Which files does FileExporter download?" below, for examples.
   B) run manual steps to pick up where FileExporter likely crashed:
      1) open a Command Prompt
      2) in the Command Prompt, navigate to the "FileExporter" folder
      3) for Attachments:
           type "cscript Step3a-ReadBody" (without the quotation marks)
         for Content:
           type "cscript Step3cv-ReadBody" (without the quotation marks)
         for Documents:
           type "cscript Step3d-ReadBody" (without the quotation marks)
      4) close the Command Prompt
      5) for Attachments:
           double-click "Step4a-DecryptBody.bat"
         for Content:
           double-click "Step4cv-DecryptBody.bat"
         for Documents:
           double-click "Step4d-DecryptBody.bat"
      6) for Attachments:
           (skip this step)
         for Content:
           double-click "Step5cv-ReplaceFileType.bat"
         for Documents:
           (skip this step)
      7) for Attachments:
           (skip this step)
         for Content:
           double-click "Step6cv-AddFileType.bat"
         for Documents:
           double-click "Step6d-AddType.bat"
      8) for Attachments:
           double-click "Step7a-RenameFile.bat"
         for Content:
           double-click "Step7cv-RenameFile.bat"
         for Documents:
           double-click "Step7d-RenameFile.bat"

Q: "In which folder are the Attachments/Content/Documents downloaded?"
A: By default, the downloaded files are extracted to a subfolder of 
   FileExporter's location, either "Exported Attachments", "Exported
   Content", or "Exported Documents".  The raw CSVs extracted from 
   Salesforce are saved to a subfolder called "CSVs".  Right before 
   quitting, FileExporter offers the option to move the files to another 
   location.

Q: "How fast is FileExporter?"
A: FileExporter's speed depends on the number of documents, the size of the 
   documents, and your internet connection speed.  After downloading data
   from Salesforce, FileExporter needs a few extra moments (usually no more 
   than one minute) to convert the data into distinct files.
   
Q: "Which files does FileExporter download?"
A: FileExporter downloads ALL files of the object type selected (Attachments,
   Content, or Documents).  There is no interface to download specific files.
   HOWEVER, the first line of the "beans.xml" configuration file can be 
   modified to download solely the files you want.
   
   Example #1: let's say I only want to download Attachments created on or 
   after December 31, 2012. I need to change the first line of "beans.xml", 
   the one that reads
		<!ENTITY whereClause "CreatedDate&gt;1900-01-01T00:00:00.000Z">
   to instead read
		<!ENTITY whereClause "CreatedDate&gt;2012-12-31T00:00:00.000Z">
   The "&gt;" is the way you write a "greater-than" symbol in an XML file.

   Example #2: if I only want to extract Accounts' Attachments, I would 
   change the "CreatedDate&gt;1900-01-01T00:00:00.000Z" clause in the first 
   line of "beans.xml" to instead read "ParentId LIKE '001%'" (without 
   the doublequotes).

   Example #3: if I only want to extract Excel Attachments, I would change 
   the "CreatedDate&gt;1900-01-01T00:00:00.000Z" clause in the first line of 
   "beans.xml" to instead read "Name LIKE '%.XLS' OR Name LIKE '%.XLSX'" 
   (without the doublequotes).

   This doesn't cover everything, but hopefully it'll be enough to get you 
   started.  You can try using Data Loader or Force.com Explorer to create 
   SOQL queries via trial and error, too.

CREDITS
   I owe many thanks to...
   ...Sanket Deshmukh for his help with command-line switches
   ...Michael Fitzgerald for his VBScript code improvements
   ...Ritchie Lawrence for his MTEE utility
   ...Mike Meyer for his testing and documentation
   The app wouldn't be the same without you! And if you've got a good idea, 
   please let me know. Open-source software depends on user feedback!
   
FEEDBACK
   Questions/bug reports/suggestions?  Email <acumen@gmail.com>.  Thanks!