Программно переименовать номера файлов с VBScript - PullRequest
0 голосов
/ 17 февраля 2012

Я думаю, что хочу использовать VBScript, но могу использовать командный файл.

Я хочу переименовать некоторые мои файлы, которые названы так:

Season (1)
Season (2)
..snip..
Season (9)
Season (10)
Season (11)
Season (12)

до:

Season (01)
Season (02)
..snip..
Season (09)
Season (10)
Season (11)
Season (12)

Вместо того, чтобы делать это вручную для 100+ сериалов, которые у меня есть более 10 сезонов, есть ли способ достичь этого программно? Спасибо.

Ответы [ 2 ]

1 голос
/ 18 февраля 2012

В VBScript вы можете сделать что-то вроде этого:

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder("C:\test")

For i = 1 To 15
    strPath = objFolder.Path & "\Season (" & i & ")"
    If Not objFso.FolderExists(strPath) Then objFso.CreateFolder strPath
Next

For Each objSubfolder In objFolder.SubFolders
    strName = objSubfolder.Name
    intPos1 = InStr(strName, "(")
    intPos2 = InStr(strName, ")")
    strOrder = Mid(strName, intPos1 + 1, intPos2 - intPos1 - 1)
    If Len(strOrder) = 1 Then
        objSubfolder.Name = Left(strName, intPos1) _
                            & "0" & strOrder _
                            & Right(strName, Len(strName) - intPos2 + 1)
    End If
Next

Это позволит просмотреть каждую подпапку в данной папке и найти номер сезона.Если это одна цифра, она дополняет этот номер и переименовывает папку.Код протестирован и работает.

0 голосов
/ 17 февраля 2012

В VB / VBA это будет что-то вроде:

For x = 1 to 100 ' or however many you have
Name "Season (" & cstr(x) & ")" as "Season (" & Format(x,"00") & ")"
Next

Или это (опять же в VB / VBA) может генерировать команды, которые вам понадобятся в файле bat:

Sub Thing()

Dim x As Long

For x = 1 To 100 ' or however many you have
  Debug.Print "Ren " & Chr$(34) & "Season (" & CStr(x) & ")" & Chr$(34) & " " _
  & Chr$(34) & "Season (" & Format(x, "00") & ")" & Chr$(34)
Next

End Sub

чтобы дать вам это:

Ren "Season (1)" "Season (01)"
Ren "Season (2)" "Season (02)"
Ren "Season (3)" "Season (03)"
Ren "Season (4)" "Season (04)"
Ren "Season (5)" "Season (05)"
Ren "Season (6)" "Season (06)"
Ren "Season (7)" "Season (07)"
Ren "Season (8)" "Season (08)"
Ren "Season (9)" "Season (09)"
Ren "Season (10)" "Season (10)"
Ren "Season (11)" "Season (11)"
Ren "Season (12)" "Season (12)"
Ren "Season (13)" "Season (13)"
Ren "Season (14)" "Season (14)"
Ren "Season (15)" "Season (15)"
Ren "Season (16)" "Season (16)"
Ren "Season (17)" "Season (17)"
Ren "Season (18)" "Season (18)"
Ren "Season (19)" "Season (19)"
Ren "Season (20)" "Season (20)"
Ren "Season (21)" "Season (21)"
Ren "Season (22)" "Season (22)"
Ren "Season (23)" "Season (23)"
Ren "Season (24)" "Season (24)"
Ren "Season (25)" "Season (25)"
Ren "Season (26)" "Season (26)"
Ren "Season (27)" "Season (27)"
Ren "Season (28)" "Season (28)"
Ren "Season (29)" "Season (29)"
Ren "Season (30)" "Season (30)"
Ren "Season (31)" "Season (31)"
Ren "Season (32)" "Season (32)"
Ren "Season (33)" "Season (33)"
Ren "Season (34)" "Season (34)"
Ren "Season (35)" "Season (35)"
Ren "Season (36)" "Season (36)"
Ren "Season (37)" "Season (37)"
Ren "Season (38)" "Season (38)"
Ren "Season (39)" "Season (39)"
Ren "Season (40)" "Season (40)"
Ren "Season (41)" "Season (41)"
Ren "Season (42)" "Season (42)"
Ren "Season (43)" "Season (43)"
Ren "Season (44)" "Season (44)"
Ren "Season (45)" "Season (45)"
Ren "Season (46)" "Season (46)"
Ren "Season (47)" "Season (47)"
Ren "Season (48)" "Season (48)"
Ren "Season (49)" "Season (49)"
Ren "Season (50)" "Season (50)"
Ren "Season (51)" "Season (51)"
Ren "Season (52)" "Season (52)"
Ren "Season (53)" "Season (53)"
Ren "Season (54)" "Season (54)"
Ren "Season (55)" "Season (55)"
Ren "Season (56)" "Season (56)"
Ren "Season (57)" "Season (57)"
Ren "Season (58)" "Season (58)"
Ren "Season (59)" "Season (59)"
Ren "Season (60)" "Season (60)"
Ren "Season (61)" "Season (61)"
Ren "Season (62)" "Season (62)"
Ren "Season (63)" "Season (63)"
Ren "Season (64)" "Season (64)"
Ren "Season (65)" "Season (65)"
Ren "Season (66)" "Season (66)"
Ren "Season (67)" "Season (67)"
Ren "Season (68)" "Season (68)"
Ren "Season (69)" "Season (69)"
Ren "Season (70)" "Season (70)"
Ren "Season (71)" "Season (71)"
Ren "Season (72)" "Season (72)"
Ren "Season (73)" "Season (73)"
Ren "Season (74)" "Season (74)"
Ren "Season (75)" "Season (75)"
Ren "Season (76)" "Season (76)"
Ren "Season (77)" "Season (77)"
Ren "Season (78)" "Season (78)"
Ren "Season (79)" "Season (79)"
Ren "Season (80)" "Season (80)"
Ren "Season (81)" "Season (81)"
Ren "Season (82)" "Season (82)"
Ren "Season (83)" "Season (83)"
Ren "Season (84)" "Season (84)"
Ren "Season (85)" "Season (85)"
Ren "Season (86)" "Season (86)"
Ren "Season (87)" "Season (87)"
Ren "Season (88)" "Season (88)"
Ren "Season (89)" "Season (89)"
Ren "Season (90)" "Season (90)"
Ren "Season (91)" "Season (91)"
Ren "Season (92)" "Season (92)"
Ren "Season (93)" "Season (93)"
Ren "Season (94)" "Season (94)"
Ren "Season (95)" "Season (95)"
Ren "Season (96)" "Season (96)"
Ren "Season (97)" "Season (97)"
Ren "Season (98)" "Season (98)"
Ren "Season (99)" "Season (99)"
Ren "Season (100)" "Season (100)"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...