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

本站现有博文318篇,共被浏览749111

本站已经建立2401天!

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