Giter VIP home page Giter VIP logo

folder-cloner's Introduction

Folder Cloner

Short script to duplicate ("clone") a directory and its contents. However, clones never come out exactly like their source material, so this script allows for text-based changes to be built into all Word files contained in the cloned directory.

About The Project

Folder Cloner Example Use

Ever had the tedious task of duplicating a Microsoft Word file and making small changes to the text throughout the document? Find and Replace is a valuable friend.

But what if your task requires multiple Word Docs to be changed? You'd need to open each document to use our friend Find and Replace. Not challenging, just time-consuming.

Let's add another layer to this onion. Let's say that instead of duplicating a set of Word files once, you needed to make multiple duplicates, each with small changes throughout. Now the time you're spending searching and replacing the text in all those documents has become quite the chore.

Sure, you could use Word's Templating System, but that requires time and effort to build a template for each base file you want to duplicate. Maybe you've been given a set of files that you didn't create, but the changes need to be made throughout.

Enter the Folder Cloner.

The Folder Cloner is a small script that abstracts away all those steps of finding and replacing strings in Word documents so you can focus on getting your updated information where it needs to go. Provide the Folder Cloner a directory to clone and a dictionary of terms to replace, and it does the rest.

The Folder Cloner applies changes to all .doc and .docx files in a provided directory, but all cloned files are rewritten in .doc format only.

Replacement string changes are made:

  • in the newly cloned folder name
  • in the file names of all newly cloned documents
  • inside the main body of all newly cloned documents
  • inside all headers and footers of all newly cloned documents
  • inside all tables and nested tables of all newly cloned documents

Note: The Folder Cloner only supports the Windows platform at the moment.

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

In order to use the Folder Cloner, you must first have Python and pip installed on your system. If you need assistance installing these prerequisites, see the folowing steps:

  • Python is a programming language. All of this project's code base is written in Python. Download the latest version of Python and install onto your local machine.

  • Pip is the package installer for Python. Once Python is installed, open your local machine's command line and use the following command to utilize Python to install Pip:

python get-pip.py -g

Git is a version control system. In this project, Git is used to clone (copy) the most up-to-date project files from GitHub to your local machine. Download the latest version of git and install on your local machine.

This project also relies on the underlying function of Microsoft Word to edit .doc and .docx files. A local installation of Microsoft Word is required to run this script. All other filetypes are duplicated into the cloned folders, but are not modified.

Installation

  1. Open the command line on your local machine.

  2. Enter the following command to use Git to clone this repository to your local machine.

git clone https://github.com/asa-leholland/folder-cloner.git
  1. Enter the following command to use Pip to install this repository's dependencies.
pip install -r requirements.txt

Usage

To use the Folder Cloner once installed, open the main.py file and add the following line item to the file:

clone_folder(directory="", replacement_dict_list=[])

Replace the path of the directory you want to clone, and a list of dictionaries of changes you want to make to the text of your cloned files and folders (see usage example below for further information on dictionary setup).

Run the Folder Cloner by opening command line, navigating to the installation folder and running:

python main.py

Voila, your folder and its contents have been successfully cloned and changed!

Usage Example with Sample Files

To see an example of the Folder Cloner, navigate to the //sample test directory of this project. This folder contains a subfolder that we want to clone. This subfolder contains a few Word files filled with boilerplate text.

Folder Cloner Use Example Original File

Then, navigate to the root directory of this project and open up the clone_test.py file.

Inside, the rep_list variable is what is used to set the changes we want to make on the cloned folders and files. rep_list contains a list of dictionaries. Each element of the list (each dictionary) represents a single cloned/duplicate folder we want to create. So, in the example of the rep_list in the //sample test directory, we will be creating three folders from our root directory, each which will receive unique changes to the file names, folder name, and content.

rep_list = [
	{'Ipsum': 'Python\'s Something Completely Different', 'Lorem': 'Monty ', '123': 'foobar'}, 
	{'Ipsum': 'Python\'s Life of Brian', 'Lorem': 'Monty', '123': 'barfoo'},
	{'Ipsum': 'Python\'s Holy Grail', 'Lorem': 'Monty', '123': 'foofoo'}, 
]

Each dictionary in the rep_list contains key:value pairs separated by commas. Each key is a string that will be searched for in the document, and each corresponding value is a replacement string that will be used whenever the key is matched. So, in the first dictionary of rep_list:

{'Ipsum': 'Python\'s Something Completely Different', 'Lorem': 'Monty ', '123': 'foobar'}, 

... we can see that the string 'Ipsum' will be replaced by the string 'Python\'s Something Completely Different', and so on.

Finally, to see the Folder Cloner in action, open the command line, navigate to the installation folder and run:

python clone_test.py

This duplicates our original folder (incorporating replacements into the folder name)...

Folder Cloner Use Example Folders Result

...as well as making all desired replacements to the file names and content within each word document:

Folder Cloner Use Example Files Result

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Asa LeHolland - [email protected]

Project Link: https://github.com/asa-leholland/folder-cloner

Acknowledgements

folder-cloner's People

Contributors

asa-holland avatar

Watchers

 avatar

folder-cloner's Issues

Case of replaced string matches that of original string, not that of the surrounding text

If a Word doc contains a run of text that is a different case than that of the surrounding text, and that string is replaced in the Clone process, the resulting string matches the case of the original text, which might result in undesired effects in the Word docs created.

For example, if the string "John Smith has duel citizenship in the USA and in Mexico." is found in a word doc and "USA" is to be replaced by "United States of America", the resulting string in the cloned documents will be "John Smith has duel citizenship in the UNITED STATES OF AMEREICA and in Mexico."

This StackOverflow discussion may be useful in addressing this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.