Clement P
asked on
Vb Script- Error in CopyFile Method using wildcard
Hi experts,
I am getting the error msg "Path not found, Code: 800A004C" while running the attached VB script
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objFile = objFSO.OpenTextFile("D:\Sc annerTesti ng\Watch Directory\scanned no\scanner.txt", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg","L :\" &arrFileLines(l) & ".jpg",False
Msgbox arrFileLines(l)
Next
What I am trying to do over here is copy the image (there is only one image file) from the directory "D:\ScannerTesting\Watch Directory\Images\" and paste it some where else and change the name of the file. The name of the image file in "D:\ScannerTesting\Watch Directory\Images\" is constantly changing, that is why, I am using the wildcard feature
The sript works fine if I hard code the name of the image file to be copied..however it gives me error mentioned above when I am using a wildcard.
Can you please tell me where I am getting it wrong as I got the syntax to use the wilcard from microsoft msdn site
http://msdn.microsoft.com/en-us/library/e1wf9e7w(VS.85).aspx
Thanks in advance
I am getting the error msg "Path not found, Code: 800A004C" while running the attached VB script
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.Fi
Set objFile = objFSO.OpenTextFile("D:\Sc
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Set objFSO = CreateObject("Scripting.Fi
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg","L
Msgbox arrFileLines(l)
Next
What I am trying to do over here is copy the image (there is only one image file) from the directory "D:\ScannerTesting\Watch Directory\Images\" and paste it some where else and change the name of the file. The name of the image file in "D:\ScannerTesting\Watch Directory\Images\" is constantly changing, that is why, I am using the wildcard feature
The sript works fine if I hard code the name of the image file to be copied..however it gives me error mentioned above when I am using a wildcard.
Can you please tell me where I am getting it wrong as I got the syntax to use the wilcard from microsoft msdn site
http://msdn.microsoft.com/en-us/library/e1wf9e7w(VS.85).aspx
Thanks in advance
sorry,
you have to create a directory arrFileLines(l) before you move the files.
you have to create a directory arrFileLines(l) before you move the files.
this line is trying to copy multiple files under one single name
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg","L :\" &arrFileLines(l) & ".jpg",False
how it is possible ?
try the below code
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg","L
how it is possible ?
try the below code
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("D:\ScannerTesting\Watch Directory\scanned no\scanner.txt", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Set objFSO = CreateObject("Scripting.FileSystemObject")
dirName = "L:\" & arrFileLines(l)
objFSO.CreateFolder(dirName),
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg", "L:\" & arrFileLines(l) & "\", False
Msgbox arrFileLines(l)
Next
replace this line
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg", "L:\" & arrFileLines(l) & "\", False
to
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg", dirName , False
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg", "L:\" & arrFileLines(l) & "\", False
to
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg", dirName , False
ASKER
Hi,
Thanks for your quick response. I am not really good at Vb scripting.
I have tried the script that you have sent. Basically this is not what I was trying to do
The scripting needs to copy and rename the file at the same time
e.g. I have a file called "Sunset.jpg" in "D:\ScannerTesting\Watch Directory\Images\", I would want it to be moved in the directory "L:\" and rename it to contents of the array "arrFileLines(l)".jpg (if arrFileLines(l)=2233555, then the file should be renamed to 2233555.jpg)
Please let me know if it's not clear or if this is the right approach to do the task
Many thanks in advance
Thanks for your quick response. I am not really good at Vb scripting.
I have tried the script that you have sent. Basically this is not what I was trying to do
The scripting needs to copy and rename the file at the same time
e.g. I have a file called "Sunset.jpg" in "D:\ScannerTesting\Watch Directory\Images\", I would want it to be moved in the directory "L:\" and rename it to contents of the array "arrFileLines(l)".jpg (if arrFileLines(l)=2233555, then the file should be renamed to 2233555.jpg)
Please let me know if it's not clear or if this is the right approach to do the task
Many thanks in advance
tell me onething
suppose i have 10 files in this folder D:\ScannerTesting\Watch Directory\Images\
do you have 10 numbers in the D:\ScannerTesting\Watch Directory\scanned no\scanner.txt file ?
suppose i have 10 files in this folder D:\ScannerTesting\Watch Directory\Images\
do you have 10 numbers in the D:\ScannerTesting\Watch Directory\scanned no\scanner.txt file ?
ASKER
there will be only one file in the folder D:\ScannerTesting\Watch Directory\Images\
and
there will be only one file (a barcode number) in the folder D:\ScannerTesting\Watch Directory\scanned no\scanner.txt file
and
there will be only one file (a barcode number) in the folder D:\ScannerTesting\Watch Directory\scanned no\scanner.txt file
ASKER
Please ignore my last message.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again for your quick reply
TRied the code attached in your previous comment, it is giving me error
Line: 32
Char:54
Error: Expected end of statement
Code: 800A0401
wanted to ask you, how would the code change if I had more than one file in the folder D:\ScannerTesting\Watch Directory\Images\ (let's say 3 files)
and only one file (a barcode number) in the folder D:\ScannerTesting\Watch Directory\scanned no\scanner.txt file
And i want all these three images to acuire the name from the single file with the barcode numbers separated by incremental numbers like 1, 2 and so on
e.g. the three files in the image folder bwould be named as
2233555_1.jpg
2233555_2.jpg
2233555_3.jpg
Many Thanks in advance
TRied the code attached in your previous comment, it is giving me error
Line: 32
Char:54
Error: Expected end of statement
Code: 800A0401
wanted to ask you, how would the code change if I had more than one file in the folder D:\ScannerTesting\Watch Directory\Images\ (let's say 3 files)
and only one file (a barcode number) in the folder D:\ScannerTesting\Watch Directory\scanned no\scanner.txt file
And i want all these three images to acuire the name from the single file with the barcode numbers separated by incremental numbers like 1, 2 and so on
e.g. the three files in the image folder bwould be named as
2233555_1.jpg
2233555_2.jpg
2233555_3.jpg
Many Thanks in advance
ASKER
The solution was not as I had expected. I had to redefine my requirements and chose a different route to solve the problem
objFSO.CopyFile "D:\ScannerTesting\Watch Directory\Images\*.jpg", "L:\" & arrFileLines(l) & ".jpg", False
you have to scan your jpg folder and pick one by one and you have to do copyfile