数状态"置疑"据库中怎么对文件进行批量重命名

数状态"置疑"据库中怎么对文件进行批量重命名,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

数状态"置疑"据库如何对文件进行批量重命名

1。新建自定义函数:从最后一个特定字符开始截取字符串

createfunctionfn_GetLastCharIndex (@Charsvarchar (1000), @Charvarchar (10)) returnsvarchar (1000) begindeclare@iintset@i=CharIndex (@Char @Chars)而(@i> 0) beginset@Chars=子串(@Chars @i + 1, len (@Chars)) set@i=CharIndex (@Char @Chars) endreturn@Charsend

2。获取文件名列表

ifexists (select * fromtempdb . . sysobjectswhereid=object_id (tempdb…# & # 39;临时# 39;))droptable # tempcreatetable #临时(filenamesvarchar (1000)) Insertinto #临时(文件名)Execmaster . . xp_cmdshell # 39; dirF: \灌篮高手——全国大赛全彩版& # 39;

数状态"置疑"据库如何对文件进行批量重命名

3。重命名

declare@FileNamevarchar (1000), @NewFileNamevarchar (1000), @svarchar (1000) declarecur_1cursorforselectdbo.fn_GetLastCharIndex(文件名,& # 39;& # 39;)FileNamefrom # tempwhereRight(文件名,4)(& # 39;jpg # 39;) andfilenameslike& # 39; %灌篮高手% & # 39;orderby1opencur_1fetchcur_1into@FileNamewhile (@@fetch_status=0) beginset@NewFileName=取代(@FileName, dbo.fn_GetLastCharIndex (@FileName & # 39; & # 39;)、右(& # 39;00 & # 39;+ dbo.fn_GetLastCharIndex (@FileName & # 39; & # 39;), 7)) set@s=& # 39; renF: \灌篮高手——全国大赛全彩版\ & # 39;+ @FileName + & # 39; & # 39; + @NewFileNameExecmaster . . xp_cmdshell@s no_outputfetchcur_1into@FileNameenddeallocatecur_1

关于数状态"置疑"据库中怎么对文件进行批量重命名问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。

数状态"置疑"据库中怎么对文件进行批量重命名