Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How VBS batch renames files and backs up original files before operation

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how VBS batch renamed files and backup the original files before the operation, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Kernel function

'= =' 'VBScript Source File-- Created with SAPIEN Technologies PrimalScript 4.0' NAME:''AUTHOR: Microsoft, Microsoft' DATE: 2014 NAME:' COMMENT: 'batch modify all the corresponding file names under the folder' = = 'choose my computer as the root directory To select the directory Const MY_COMPUTER = & H11&Const WINDOW_HANDLE = 0Const OPTIONS = 0Set objShell = CreateObject ("Shell.Application") Set objFolder = objShell.Namespace (MY_COMPUTER) Set objFolderItem = objFolder.SelfstrPath = objFolderItem.PathSet objShell = CreateObject ("Shell.Application") Set objFolder = objShell.BrowseForFolder _ (WINDOW_HANDLE, "Select a folder:", OPTIONS StrPath) If objFolder Is Nothing ThenWscript.QuitEnd IfSet objFolderItem = objFolder.SelfobjPath = objFolderItem.Path'MsgBox objFolderItem.name'=' Select the directory 'Const WINDOW_HANDLE = 0' Const OPTIONS = 0'' Set objShell = CreateObject ("Shell.Application") 'Set objFolder = objShell.BrowseForFolder _' (WINDOW_HANDLE, "Select a folder:", OPTIONS) under the specified drive letter "C:\")''If objFolder Is Nothing Then' Wscript.Quit' End If' 'Set objFolderItem = objFolder.Self' objPath = objFolderItem.Path'' MsgBox objPath'====' defines the variable dim file_path,prefix_name,suffix_name,repeat_name,repeat_editDim OneLine,TwoLine,ThreeLine,FourLine FiveLinei=0test = createobject ("Scripting.FileSystemObject") .GetFile (Wscript.ScriptFullName). ParentFolder.Path'Wscript.echo testfilepath=test& "\ config.ini" 'WScript.Echo filepath' file_path= "C:\ Users\ Administrator\ Desktop\ 1\ music"' path to the destination folder dst_file_path= "C:\" & objFolderItem.name& "_ bak" file_path=objPath'- get the folder path And open the configuration file Set fso = CreateObject ("Scripting.FileSystemObject") Set folder = fso.getfolder (file_path) Set fs = folder.filesSet file=fso.OpenTextFile (filepath,1)'- before the operation Back up the original file fso.CopyFolder file_path,dst_file_path,True'--' take out the two numbers in the first line OneLine=file.ReadLineOneLineStr=Split (OneLine, "=") OneLineCount=UBound (split (OneLine) "=") For i1 / 0 To OneLineCount'WScript.Echo OneLineStr (i1) Next'- 'take out the two numbers in the second line TwoLine=file.ReadLineTwoLineStr=Split (TwoLine, "=") TwoLineCount=UBound (split (TwoLine) "=") For i2'0 To TwoLineCount'WScript.Echo TwoLineStr (i2) Next'- 'take out the two numbers in the third line ThreeLine=file.ReadLineThreeLineStr=Split (ThreeLine, "=") ThreeLineCount=UBound (split (ThreeLine) "=") For i3'0 To ThreeLineCount'WScript.Echo ThreeLineStr (i3) Next'- 'take out the two numbers in the fourth line FourLine=file.ReadLineFourLineStr=Split (FourLine, "=") FourLineCount=UBound (split (FourLine) "=") For i4 To FourLineCount'WScript.Echo FourLineStr (i4) Next'--' takes out the two numbers in the fifth line FiveLine=file.ReadLineFiveLineStr=Split (FiveLine, "=") FiveLineCount=Ubound (split (FiveLine) "=") For i5) 0 To FiveLineCount'WScript.Echo FiveLineStr (i5) Next'- 'calling procedure' Function_Main () Function Function_Main () If OneLineStr (1) = "true" ThenFunction_Prefix_Name () Elseif OneLineStr (1) = "false" ThenFunction_Suffix_Name () Elseif OneLineStr (1) = " Number "ThenFunction_Number_Value () Elseif OneLineStr (1) =" array "ThenFunction_MyArrayReName () Elseif OneLineStr (1) ="ThenWScript.QuitEnd IfEnd Function'--'add the prefix Function Function_Prefix_Name () For Each file in fsFile.Name=TwoLineStr (1) & File.NameNextEnd Function'- to the original name -- 'add the suffix Function Function_Suffix_Name () For Each file in fsName=Mid (file.name) to the original name 1 file.name instrrev (".")-1) 'get it. The file name before the number Format=Mid (file.name,instrrev (file.name, ".")) 'get it. The suffix format file.Name=Name&ThreeLineStr (1) & FormatNextEnd Function'----' adds an ordered self-incrementing number Function Function_Number_Value () For Each file In fsFourLineStr (1) = FourLineStr (1) + 1file.name=FourLineStr (1) & file.nameNextEnd Function' Function_Suffix_Name ()'- before the original name. -'batch change of file name Function Function_MyArrayReName () Const BeforAlarm='. Prison riot occurred. Please note that the prisoners broke out in "Const AfterAlarm=" and the teams disposed of "Dim MyArray (12) n=1y=0For item0 To 12If item11 Then MyArray (I) =" Elseif outpost "Elseif item12 Then MyArray (I) =" self-guard "Else MyArray (I) = n &" sentry "n=n+1End If 'WScript.Echo MyArray (I) Next For Each file In fsFormat=Mid (file.name,instrrev (file.name,". ") 'MsgBox Format'MsgBox MyArray (y) If FiveLineStr (1) = "before" Then file.name=MyArray (y) & BeforAlarm&FormatElseif FiveLineStr (1) = "after" Then file.name=MyArray (y) & AfterAlarm&FormatElse MsgBox "Please set it before or after confirmation!" "hint" WScript.QuitEnd If y=y+1'WScript.Echo file.nameNextEnd Function'= ='If prefix_name "" then' batch prefix 'For each f in fs' f.name = prefix_name&f.name' Next' End If'' if suffix_name "" then' batch suffix 'For each f in fs' name = Mid (f. Namemay1 format InstrRev (f.name, ".")-1)' format = Mid (f.namememery InstrRev (f.name, "."))' F.name = name & suffix_name & format' Next' end If''if repeat_name "" then' batch deletes the same characters' For each f in fs' On Error Resume Next' f.name = Replace (f. NameMagic repeatable edit) 'Next' end If''-file operation ends''set fso = nothing' frees memory' 'MsgBox ("done!")

Configuration files are required

Content of config.ini file: statue=prefix_name= [320kbp] suffix_name= [end] iFeb 20140100array =

How to configure parameters:

Statue=true to increase the prefix statue=false, to increase the suffix statue=number is to increase the ordered self-increment number. Statue=array to call the array function statue= null value is empty, no processing, exit the script operation. When array=before, set to before confirmation. When array=after, set to after confirmation. When array= is empty, a prompt pops up to exit the script operation.

The above is all the contents of the article "how to rename files in batches and back up original files before operation by VBS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report