原创 连续剧重命名小工具

2011-1-8 22:54 2127 9 9 分类: 软件与OS

网上下载的连续剧,往往名字很长,如"[TSKS][snow queen][001][ko_cn].rmvb",MP4和电视上显示时,由于名字太长,没办法显示是哪一集的,所以在放到存储卡之前要改名.但逐个改太麻烦了,批量处理工具又过于烦锁,不如自己写个小工具去掉文件名多余的部分.


通过批处理文件传递需要去掉字符串,程序得到字符串后,用replace把字符串用空字符串代替,非常简单.


代码如下:


Sub Main()
    Dim NoFileMoved As Boolean = True
    Dim LogFileName As String
    LogFileName = My.Application.Info.DirectoryPath & "\Log.txt"
    Dim LogFileWriter As New StreamWriter(LogFileName, False, System.Text.Encoding.Default)
    Try
        Dim ArgsCount As Integer
        Dim Args As [String]() = Environment.GetCommandLineArgs()


        If Args.Length < 2 Then
            Exit Sub
        End If


        ArgsCount = Args.Length


        Dim dInfo As New DirectoryInfo(My.Application.Info.DirectoryPath)


        For Each fInfo As FileInfo In dInfo.GetFiles
            '忽略本程序,忽略LOG文件,忽略BAT文件
            If (fInfo.Name <> My.Application.Info.AssemblyName) And (fInfo.FullName <> LogFileName) And (fInfo.Extension <> ".bat") Then
                Dim NewFInfo As FileInfo
                Dim NewFileName As String = fInfo.FullName


                '去掉命令行参数指定的字符串
                For i = 1 To ArgsCount - 1
                    NewFileName = NewFileName.Replace(Args(i), "") '清空指定字符
                Next


                NewFInfo = New FileInfo(NewFileName)
                If fInfo.Name <> NewFInfo.Name Then
                    '重命名
                    File.Move(fInfo.FullName, NewFileName)


                    Console.WriteLine("原文件:" & fInfo.Name)
                    Console.WriteLine("----->:" & NewFInfo.Name)


                    LogFileWriter.WriteLine("原文件:" & fInfo.Name)
                    LogFileWriter.WriteLine("----->:" & NewFInfo.Name)


                    NoFileMoved = False
                End If
            End If
        Next
    Catch ex As Exception
        Console.WriteLine(ex.ToString)
        LogFileWriter.WriteLine(ex.ToString)
    Finally
        LogFileWriter.Flush()
        LogFileWriter.Close()
    End Try
    If NoFileMoved = False Then
        Console.WriteLine("按任意键继续...")
        Console.ReadLine()
    End If
End Sub


重命名前:


274f593f-49f3-4e56-8e68-b245abb116e0.jpg


重命名后:


54e74ec4-88ef-415a-b71e-f43de9740745.jpg


 


可执行文件下载链接:


attachment download


 <梅川酷子原创>

文章评论0条评论)

登录后参与讨论
我要评论
0
9
关闭 站长推荐上一条 /2 下一条