EADST

Copy and Rename File When Existing Same Name

Python: Copy and Rename File When Existing Same Name

import os
import shutil

def rename_copy(file_path, out_dir):
    name = os.path.basename(file_path)
    if not os.path.exists(os.path.join(out_dir, name)):
        save_path = os.path.join(out_dir, name)
        shutil.copy(file_path, save_path)
    else:
        base, extension = os.path.splitext(name)
        print(base, extension)
        i = 1
        while os.path.exists(os.path.join(out_dir, '{}_{}{}'.format(base, i, extension))):
            i += 1
        save_path = os.path.join(out_dir, '{}_{}{}'.format(base, i, extension))
        shutil.copy(file_path, save_path)
    return save_path

path = "./copy/"
input_path = "test.jpg"
print(path, safe_copy(input_path, path))
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
SVR hf transformers Miniforge C++ Diagram tqdm SAM ChatGPT GPT4 顶会 Qwen llama.cpp TensorFlow Quantization Algorithm Use v0.dev Knowledge ONNX Pytorch Search Pickle 签证 LoRA Agent Conda Vmess 阿里云 SPIE PyTorch 域名 Pandas Firewall uwsgi Paper BTC Statistics UI OpenCV IndexTTS2 HuggingFace Qwen2.5 Streamlit LLAMA TSV LaTeX Distillation Pillow 搞笑 图形思考法 Magnet 公式 关于博主 FP64 多线程 VGG-16 WebCrawler YOLO diffusers 净利润 第一性原理 LeetCode Jetson Domain SQLite XML Transformers DeepStream 继承 AI OCR Data mmap icon Nginx Math CEIR Cloudreve Python Image2Text Llama ModelScope 算法题 Zip Color Input 音频 Ubuntu Tiktoken uWSGI News Random Hungarian XGBoost Docker SQL FP32 Proxy Windows Video 图标 WAN Vim Markdown CLAP scipy CTC Template 版权 TTS Card Qwen2 CC Shortcut Ptyhon ResNet-50 NLTK Password Land BF16 Clash git-lfs Sklearn Plate Linux NLP Quantize GIT MD5 InvalidArgumentError GGML Logo Git Food PDB VSCode GPTQ Rebuttal Google 腾讯云 VPN DeepSeek UNIX Bin FP16 EXCEL Crawler Numpy Heatmap torchinfo 强化学习 PDF Permission Interview Plotly Hotel Bipartite RAR Base64 FP8 tar 飞书 Paddle 云服务器 FastAPI HaggingFace Bitcoin Translation git 证件照 Freesound Claude Attention Safetensors PyCharm Animate LLM Dataset v2ray RGB GoogLeNet Michelin Web BeautifulSoup Jupyter QWEN Datetime PIP Tensor CUDA Website Github CSV Mixtral Django FlashAttention 多进程 CAM Disk Anaconda API TensorRT OpenAI Hilton Breakpoint Excel JSON logger 报税 递归学习法 NameSilo Review Tracking Baidu Bert Augmentation printf COCO 财报 Gemma CV
站点统计

本站现有博文323篇,共被浏览796086

本站已经建立2493天!

热门文章
文章归档
回到顶部