VBSによるファイル名の一括変更と操作前のオリジナルファイルのバックアップ
2022-01-01 21:59:56
主な機能
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME:
'
' AUTHOR: Microsoft , Microsoft
' DATE : 2014/7'
' COMMENT: ' Batch modify all the corresponding file names under the folder
'
' ==========================================================================
' Select my computer as the root directory to select the directory
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.
strPath = objFolderItem.
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", OPTIONS, strPath)
If objFolder Is Nothing Then
Wscript.Quit
End If
Set objFolderItem = objFolder.
objPath = objFolderItem.
'MsgBox objFolderItem.name
'===================================================================
'Select the directory under the specified drive
' Const WINDOW_HANDLE = 0
' Const OPTIONS = 0
'
' Set objShell = CreateObject("Shell.Application")
' Set objFolder = objShell.BrowseForFolder _
' (WINDOW_HANDLE, "Select a folder:", OPTIONS, "C:\")
'
' If objFolder Is Nothing Then
' Wscript.Quit
' End If
'
' Set objFolderItem = objFolder.
' objPath = objFolderItem.Path
'
' MsgBox objPath
'=========================================================================
' Define the variables
dim file_path,prefix_name,suffix_name,repeat_name,repeat_edit
Dim OneLine,TwoLine,ThreeLine,FourLine,FiveLine
i=0
test = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
'Wscript.echo test
filepath=test&"\config.ini"
'WScript.Echo filepath
' file_path = "C:\Users\Administrator\Desktop\1\music"'path to the target folder
dst_file_path="C:\\quot;&objFolderItem.name&"_bak"
file_path=objPath
'----- gets the folder path and opens the configuration file
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.getfolder(file_path)
Set fs = folder.files
Set file=fso.OpenTextFile(filepath,1)
'---------------- backup the original file before the operation
fso.CopyFolder file_path,dst_file_path,True
'----------------------------------
'Take out the two numbers in the first line
OneLine=file.
OneLineStr=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.
TwoLineStr=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.
ThreeLineStr=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.
FourLineStr=Split(FourLine,"=")
FourLineCount=UBound(split(FourLine,"="))
For i4=0 To FourLineCount
'WScript.Echo FourLineStr(i4)
Next
'-----------------------------------------
'Take out the two numbers in the fifth line
FiveLine=file.
FiveLineStr=Split(FiveLine,"=")
FiveLineCount=Ubound(split(FiveLine,"="))
For i5=0 To FiveLineCount
'WScript.Echo FiveLineStr(i5)
Next
'---------------------------------------------
'Call the procedure
'Function_Main()
Function Function_Main()
If OneLineStr(1)="true" Then
Function_Prefix_Name()
Elseif OneLineStr(1)="false" Then
Function_Suffix_Name()
Elseif OneLineStr(1)="number" Then
Function_Number_Value()
Elseif OneLineStr(1)="array" Then
Function_MyArrayReName()
Elseif OneLineStr(1)="" Then
WScript.Quit
End If
End Function
'-----------------------------------------
'Add a prefix to the original name
Function Function_Prefix_Name()
For Each file in fs
File.Name=TwoLineStr(1)&File.Name
Next
End Function
'--------------------------------------
'Add a suffix to the original name
Function Function_Suffix_Name()
For Each file in fs
Name=Mid(file.name,1,instrrev(file.name,". ")-1) 'Get the name of the file before the . The name of the file in front of the number
Format=Mid(file.name,instrrev(file.name,". ")) 'Get the format of the suffix after the . The format of the suffix after the number
file.Name=Name&ThreeLineStr(1)&Format
Next
End Function
'--------------------------------------------
'Add an ordered self-incrementing number before the original name
Function Function_Number_Value()
For Each file In fs
FourLineStr(1)=FourLineStr(1)+1
file.name=FourLineStr(1)&file.name
Next
End Function
'Function_Suffix_Name()
'--------------------------------------------------
'Bulk change file name
Function Function_MyArrayReName()
Const BeforAlarm="A prisoner storm occurred, please pay attention"
Const AfterAlarm="A prisoner riot occurred, the teams according to the plan to deal with"
Dim MyArray(12)
n=1
y=0
For i=0 To 12
If i=11 Then
MyArray(i)="Supervisory door sentry"
Elseif i=12 Then
MyArray(i)="Self-defense post"
Else
MyArray(i)=n&"No." MyArray(i)=n&"No."
n=n+1
End If
' WScript.Echo MyArray(i)
Next
For Each file In fs
Format=Mid(file.name,instrrev(file.name,". "))
'M
statue=false for adding suffix
statue=number to add an ordered self-incrementing number.
statue=array is to call the array function
is empty when statue=null, no processing, exit script operation.
If array=before, set to before confirmation.
array=after, set to after.
When array=empty, popup message to exit the script operation.
Well that's it for this article, mainly using the FileSystemObject and mid functions
関連
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
VBSを使用してHostsファイルのワンクリック設定コードを実装する
-
複数ディレクトリの複数ファイルを反復して一括置換するためのVBSスクリプト
-
Office一括アクティベーションのコマンドツールosppの説明
-
VBSで指定されたディレクトリにあるファイルの一覧を取得する方法
-
コンピュータのオン/オフ時間を問い合わせるためのvbsコード
-
VBSでメーカー向けクエリーサービスを実装
-
vbs と wget を組み合わせて Web サイトの画像をダウンロードする。
-
vbscriptを用いた36ビット自動増加数生成コード
-
jre パッケージをダウンロードし、サイレントにインストールする vbs スクリプトのコード例
-
Iisext.vbsでWebサービス拡張を有効にする方法