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

本站现有博文323篇,共被浏览796025

本站已经建立2493天!

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