Показать полную графическую версию : [решено] Копирование файла с маской...
Добрый день!
Не могу понять почему не отрабатывает скрипт (копирование файла с маской: SBC........._1..\.txt):
iDir1 = "D:\test2\in" ---- дир., где размещается файл
iDir2 = "D:\test2\out" ---- дир., в кот. надо скопировать
Maska = "SBC........._1..\.txt$"
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyFile ""+iDir1+"\"+Maska+"", ""+iDir2+""
Благодарю!
Dt83, где маска? Это:
"SBC........._1..\.txt$"
имя папки «SBC........._1..» и файла «.txt$».
Символами маски могут быть:
* — любое количество символов;
«?» — один символ.
Если нужно что-либо сложнее — те же регулярные выражения — создавайте объект «VBScript.RegExp» и используйте его для сравнения. Либо сразу переходите на PoSH.
P.S. Обратите внимание, как следует оформлять код тэгом [code] (http://forum.oszone.net/misc.php?do=bbcode#code).
предполагалось что : SBC........._1..\.txt маска имени файла. Дело в том что если адже явно указать имя файла, все равно ошибка выходит:
iDir1 = "D:\test2\in" ---- дир., где размещается файл
iDir2 = "D:\test2\out" ---- дир., в кот. надо скопировать
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyFile ""+iDir1+"\SBC201111236_100.txt"+iDir2+""
Petya V4sechkin
02-09-2011, 16:24
FSO.copyFile ""+iDir1+"\SBC201111236_100.txt"+iDir2+""
А куда второй параметр дели? Зачем прилепили его к первому?
Имелось в виду (поспешила):
iDir1 = "D:\test2\in" ---- дир., где размещается файл
iDir2 = "D:\test2\out" ---- дир., в кот. надо скопировать
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.copyFile ""+iDir1+"\SBC201111236_100.txt", ""+iDir2+""
Dt83, метод «.CopyFile» не может скопировать файл «D:\test2\in\SBC201111236_100.txt» в указываемый Вами файл «D:\test2\out», поскольку уже существует каталог с тем же именем. Чтобы второй параметр метода «.CopyFile» воспринимался как каталог — явно укажите на это обстоятельство:
FSO.copyFile ""+iDir1+"\SBC201111236_100.txt", ""+iDir2+"\"
Описание Вашей ошибки дано прямо в справке по методу «.CopyFile»:
Scripting Runtime Library
CopyFile Method
…
But you cannot use:
FileSystemObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder"
If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create. In either case, three things can happen when an individual file is copied.
If destination does not exist, source gets copied. This is the usual case.
If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file.
If destination is a directory, an error occurs.
An error also occurs if a source using wildcard characters doesn't match any files. The CopyFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes made before an error occurs.
…
Option Explicit
Dim strFolderSource
Dim strFolderDest
Dim strFileName
Dim strFullFileName
strFolderSource = "D:\test2\in"
strFolderDest = "D:\test2\out"
strFileName = "SBC201111236_100.txt"
With WScript.CreateObject("Scripting.FileSystemObject")
If .FolderExists(strFolderSource) Then
If .FolderExists(strFolderDest) Then
strFullFileName = .BuildPath(strFolderSource, strFileName)
If .FileExists(strFullFileName) Then
.CopyFile strFullFileName, strFolderDest & "\"
Else
WScript.Echo "Can't find [" & strFullFileName & "]"
End If
Else
WScript.Echo "Can't find [" & strFolderDest & "]"
End If
Else
WScript.Echo "Can't find [" & strFolderSource & "]"
End If
End With
WScript.Quit 0
Спасибо за код, но хочется все таки понять синтаксис. Попробовала как вы посоветовали, но все равно ссылается на то что путь не найден:
iDir1 = "D:\test2\in"
iDir2 = "D:\test2\out"
Maska = "SBC........._1..\.txt$"
Set FSO2 = CreateObject("Scripting.FileSystemObject")
FSO2.copyFile ""+iDir1+"\"+Maska+"", ""+iDir2+"\"
делаю вариант такой, ошибка та же:
iDir1 = "D:\test2\in"
iDir2 = "D:\test2\out"
Maska = "SBC........._1..\.txt$"
Set FSO2 = CreateObject("Scripting.FileSystemObject")
FSO2.copyFile ""+iDir1+"\"+Maska+"", ""+iDir2+""
Делаю вариант такой (копирование осуществляется):
iDir1 = "D:\test2\in"
iDir2 = "D:\test2\out"
Maska = "SBC........._1..\.txt$"
Set FSO2 = CreateObject("Scripting.FileSystemObject")
FSO2.copyFile ""+iDir1+"\*.txt", ""+iDir2+""
Что же с маской такое, что wsh не понимает?
Dt83, прочтите ещё раз сообщение #2 (http://forum.oszone.net/post-1744749.html#post1744749), где указано, какие символы допустимы в масках имён.
Дополнение: Microsoft Windows XP - Using wildcard characters (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/find_c_search_wildcard.mspx).
Iska, спасибо! наконец-то разобралась:)
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.