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

本站现有博文322篇,共被浏览793634

本站已经建立2491天!

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