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

本站现有博文327篇,共被浏览833574

本站已经建立2538天!

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