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

本站现有博文333篇,共被浏览922430

本站已经建立2628天!

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