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

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

本站已经建立2673天!

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