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

本站现有博文321篇,共被浏览764609

本站已经建立2442天!

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