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

本站现有博文322篇,共被浏览788486

本站已经建立2483天!

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