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

本站现有博文338篇,共被浏览972299次

本站已经建立2685天!

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