Git Product home page Git Product logo

filecontent-to-clipboard's Introduction

Filecontent-to-Clipboard

Filecontent-to-Clipboard is a handy Python script designed to streamline your programming workflow by automatically copying the content of all files OR specified files of the current directory to your clipboard.

I use it to quickly copy the content of specific files for ChatGPT prompting.

How to use

app.py

Create a folder, copy your files into it and execute this python script => Now you have the contents of the files in your clipboard

app-specified-files.py

Change the specified files inside the code to meet your needs. Now you can copy this file into your project and just execute the script whenever you need it!

The content of the clipboard will have the following structure:

file1:

CONTENT_OF_FILE1

---------

file2:

CONTENT_OF_FILE2

---------

Remember, the script does not differentiate between file types and will attempt to read all file types. Large or binary files may cause the script to fail or produce undesired results. It's best used in directories with text-based files like .txt, .csv, .xml, .html, .css, .js, .py, .php, etc.

How it works

Here's a breakdown of the script's workflow:

  • It first identifies the directory where it's currently located using Python's os module.
  • Next, it loops over all the files in the said directory.
  • It ignores itself (the script file) to prevent unnecessary content copying.
  • For each of the other files, it opens the file and reads the content.
  • Then, it builds a formatted string with the filename and its content, separated by line breaks for clarity. It also adds a line of hyphens for better visual separation between different files.
  • Once it has looped through all the files and collected their contents, it copies the compiled string into your system's clipboard using the pyperclip module.

This script allows you to quickly and efficiently copy an entire directory's file contents into your clipboard, formatted and ready to paste wherever required.

Requirements

Ensure to have pyperclip Python module installed. If not, install it using pip:

pip install pyperclip

Move the script to the directory you want to copy files from and run:

python3 app.py OR python3 app-specified-files.py

Tip: You can also change python files to be executed by Python.exe (Windows), so you can execute it with a double-click.

After successful execution, the script's output (contents of the files) is stored in the clipboard, ready for you to paste wherever you like. This script handles all text-based file types present in the directory.

filecontent-to-clipboard's People

Contributors

fragxz avatar

Watchers

 avatar

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.