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

本站现有博文337篇,共被浏览953412次

本站已经建立2663天!

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