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

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

本站已经建立2578天!

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