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

本站现有博文311篇,共被浏览742323

本站已经建立2382天!

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