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

本站现有博文332篇,共被浏览900717

本站已经建立2602天!

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