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

本站现有博文332篇,共被浏览875824

本站已经建立2583天!

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