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

本站现有博文338篇,共被浏览972351次

本站已经建立2685天!

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