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

本站现有博文321篇,共被浏览773678

本站已经建立2463天!

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