0

I wanna copy all file but not including 2 files.

Example:

/var/www/site-domain/htdocs/all files but not including .git and wp-config.php files

sorry for my english :)

  • 2
    Use https://askubuntu.com/questions/333640/cp-command-to-exclude-certain-files-from-being-copied#:~:text=Without%20the%20trailing%20slash%2C%20it,means%20archive%20mode%20and%20verbose. – Rinzwind May 20 '22 at 10:21

1 Answers1

1

Merged w/ my prev. answer: An idea would be, yes it's a long detour, but write a Python script using the OS library & then run that.

Worked on it for a lil while, the code of the Python file is down below - it's also on my GitHub in case you want the .py file itself rather than having to copy-paste it: https://github.com/n3xtd00rpanda/PythonPlayground/blob/master/copyfiles_final.py

Remember to have python3 installed, and use chmod +x to make the file executable.

Did a lot of testing, so hopefully it should work as intended! If it solved your issue, feel free to leave an upvote & choose my answer as one that satisfied your question. :-)

#!/usr/bin/env python3 

from fileinput import filename
import os, subprocess, shutil, sys
from re import search

files = []
full_file_path = ""

def fileCopy(nwd): 

    for file in os.listdir():
        file_name, file_extension = os.path.splitext(file)
        full_file_path = os.getcwd() + "/" + file_name + file_extension
        new_file_path = nwd + file_name + file_extension
        subs = ".git"
        if file_name.find(".git") == -1 and file_extension != ".git" and os.path.isfile(full_file_path) and file_name != "wp_config" and file_name != "copyfiles_nogitignore":
            print("Copying from: ", full_file_path)
            print("Copying to: ", new_file_path)
            shutil.copyfile(full_file_path, new_file_path)
        elif file_extension == ".git" or file_name.find("git") != -1 or file_name == "wp_config" and os.path.isfile(full_file_path):
            print("Found file: ", file_name, file_extension, " in working directory. Not copied.")

if __name__ == '__main__':
    fileCopy(sys.argv[1])
n3xtd00rpanda
  • 181
  • 1
  • 7