View previous topic :: View next topic |
Author |
Message |
Lari
Joined: 12 Mar 2007 Posts: 30
|
(Separately) Posted: Sun Aug 05, 2007 12:42 Post subject: Переименование файлов при перемещении в другую папку |
|
|
Здравствуйте.
Подскажите пожалуйста как можно с помощью скрипта на VB переименовать файл.
Имеется готовый скрипт, который перемещает файл под курсором в папку с именем расширения файла. Как после перемещение изменить расширение файла на другое?
Code: |
If WScript.Arguments.Count = 0 Then
MsgBox "Не указаны параметры!", vbOKOnly + vbError, "Внимание!"
Wscript.Quit
End If
Dim TempFile, FSO, SelFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TempFile = FSO.OpenTextFile(WScript.Arguments(0), 1)
Dim FileName, FilePath, DashInName, NewFilePath
Do While Not TempFile.AtEndOfStream
Set SelFile = FSO.GetFile(TempFile.ReadLine)
FileName = FSO.GetExtensionName(SelFile)
FilePath = SelFile.ParentFolder
If WScript.Arguments.Count > 1 Then
NewFilePath = WScript.Arguments(1) & FileName
Else
NewFilePath = FilePath & "\" & FileName
End If
If Not FSO.FolderExists(NewFilePath) Then
FSO.CreateFolder(NewFilePath)
End If
If Not FSO.FileExists(NewFilePath & "\" & FileName) Then
FSO.MoveFile SelFile, NewFilePath & "\"
Else
MsgBox "Уже существует файл " & FileName & " в папке " & NewFilePath, vbOKOnly + vbExclamation, "Внимание!"
End If
Loop
Set TempFile = Nothing
Set FSO = Nothing
Set SelFile = Nothing
Wscript.Quit
|
|
|
Back to top |
|
|
Batya
Joined: 15 Dec 2004 Posts: 2220 Location: Москва, Россия
|
(Separately) Posted: Mon Aug 06, 2007 14:20 Post subject: |
|
|
Например, так:
Code: |
FSO.GetFile(NewFilePath & "\" & FileName).Name = FSO.GetBaseName(NewFilePath & "\" & FileName) & ".txt"
|
Хотя, в твоем случае проще для метода MoveFile вторым параметром указывать не просто путь, а путь с новым именем файла. |
|
Back to top |
|
|
Lari
Joined: 12 Mar 2007 Posts: 30
|
(Separately) Posted: Mon Aug 13, 2007 21:12 Post subject: |
|
|
Спасибо |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|