zoukankan      html  css  js  c++  java
  • Sql Server中,文件批量重命名

    --1. 新建自定义函数:从最后一个特定字符开始截取字符串
    create function fn_GetLastCharIndex(@Chars varchar(1000),@Char varchar(10))
    returns varchar(1000)
    begin
        
    declare @i int
        
    set @i=CharIndex(@Char,@Chars)
        
    while(@i>0)
        
    begin
            
    set @Chars=Substring(@Chars,@i+1,len(@Chars))
            
    set @i=CharIndex(@Char,@Chars)
        
    end
        
        
    return @Chars
    end


    --2. 获取文件名列表
    if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp'))
    drop table #temp
    create table #temp(filenames varchar(1000))
    Insert into #temp(filenames)
    Exec master..xp_cmdshell 'dir F:\灌篮高手-全国大赛全彩版'


    --3. 重命名
    declare @FileName varchar(1000),
        
    @NewFileName varchar(1000),
        
    @s varchar(1000)
    declare cur_1 cursor for
    select dbo.fn_GetLastCharIndex(filenames,' ') FileName from #temp where Right(filenames,4in ('.jpg'and filenames like '%slamdunk%' order by 1
    open cur_1
    fetch cur_1 into @FileName
    while(@@fetch_status=0)
    begin
        
    set @NewFileName = Replace(@FileName,dbo.fn_GetLastCharIndex(@FileName,'-'),Right('00'+dbo.fn_GetLastCharIndex(@FileName,'-'),7))
        
    set @s='ren F:\灌篮高手-全国大赛全彩版\' + @FileName + ' ' + @NewFileName    
        
    Exec master..xp_cmdshell @s,no_output
    fetch cur_1 into @FileName
    end
    deallocate cur_1
  • 相关阅读:
    Java中的Math类、Array类、大数据运算
    关于VUE3 setup()中动态获取dom
    iframe内部修改iframe src链接
    vue Router4动态添加路由
    时间戳
    vue watch 中的this问题
    el-date-picker 设置事件格式为时间戳
    TP6 阿帕奇去 index.php
    dbeaver 驱动下载失败
    dbeaver mysql8+ 出现 The server time zone value '�й���׼ʱ��' ...错误
  • 原文地址:https://www.cnblogs.com/tohen/p/2116984.html
Copyright © 2011-2022 走看看