?
Solved

Vb Script- Error in CopyFile Method using wildcard

Posted on 2009-12-16
11
Medium Priority
?
603 Views
Last Modified: 2012-05-08
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.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")
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
0
Comment
Question by:Clement P
  • 6
  • 5
11 Comments
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 26063694
this line will not work.
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
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 26063713
sorry,
you have to create a directory  arrFileLines(l)  before you move the files.
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 26063757
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
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

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 26063769
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
0
 
LVL 2

Author Comment

by:Clement P
ID: 26064064
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
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 26064785
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 ?

0
 
LVL 2

Author Comment

by:Clement P
ID: 26064845
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
0
 
LVL 2

Author Comment

by:Clement P
ID: 26064943
Please ignore my last message.
0
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 300 total points
ID: 26064952
Try this
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
 
Dim objFolder
Set objFolder = objFSO.GetFolder("D:\ScannerTesting\Watch Directory\Images\")
Dim fileName( ) 
Dim i
ListDirectory objFolder
 
Sub ListDirectory(objFolder)
  Dim objFile
  Dim objSubFolder
  Dim strNewFilename
  Dim cnt
  For Each objFile In objFolder.Files
    i = 0
	fileName(i) = objFile.Name
	i=i+1
  Next
  
End Sub
 
 
For l = LBound(arrFileLines) to Ubound(arrFileLines) to  Step 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
dirName = "L:\" & arrFileLines(l)
objFSO.CreateFolder(dirName), 
objFSO.CopyFile fileName (l), dirName , False
Msgbox arrFileLines(l)
Next

Open in new window

0
 
LVL 2

Author Comment

by:Clement P
ID: 26069987
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



0
 
LVL 2

Author Closing Comment

by:Clement P
ID: 31666829
The solution was not as I had expected. I had to redefine my requirements and chose a different route to solve the problem
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question