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

本站现有博文324篇,共被浏览808742

本站已经建立2511天!

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