?
Solved

Need help modify a script

Posted on 2013-12-10
31
Medium Priority
?
389 Views
Last Modified: 2013-12-11
I need to modify this script so it looks for a file in folder "\\client\c$\barcode", that will have todays date.  i.e. 121013.txt and then copies it to \\fileserver\community files\Public Files\Barcode"

Option Explicit
Dim strSource, strDest, strFolderName, strFolderPath
Dim objFSO

strSource = "\\client\c$\photos"
strDest = "\\fileserver\community files\Public Files\Pet-Ark"

strFolderName = Right("0" & Day(Date), 2) & _
    MonthName(Month((Date))) & Year(Date) & "-LB"
   
   
strFolderPath = strSource & "\" & strFolderName


Set objFSO = CreateObject("Scripting.FileSystemObject")


objFSO.CopyFolder strFolderPath, strDest & "\" & strFolderName, True


WScript.Echo strFolderPath & " copied to " & strDest & "\" & strFolderName
0
Comment
Question by:J.R. Sitman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 15
  • 12
  • 4
31 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 39710335
You could do that, but robocopy would be simpler...

robocopy "\\client\c$\barcode" "\\fileserver\community files\Public Files\Barcode" %date:~4,2%%date:~7,2%%date:~-2%

But if you want to use that modified script...
Option Explicit
Dim strSource, strDest, strFolderName, strFolderPath
Dim objFSO

strSource = "\\client\c$\barcode"
strDest = "\\fileserver\community files\Public Files\Barcode" 
strFileName = Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
strFolderPath = strSource & "\" & strFileName

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder strFolderPath, strDest & "\" & strFileName, True

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39710373
Please change the code to copy lb121013.txt
I forgot we will be using the script at two different locations so it has to be different. Thank you
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39710431
Just add it in line 7 in sirbounty's script. So it would look like

strFileName = "lb" & Right("0" & Month(Date),2) & ....... (same code he had here)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 67

Expert Comment

by:sirbounty
ID: 39710443
Like this?
Option Explicit
Dim strSource, strDest, strFolderName, strFolderPath
Dim objFSO

strSource = "\\client\c$\barcode"
strDest = "\\fileserver\community files\Public Files\Barcode" 
strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
strFolderPath = strSource & "\" & strFileName

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder strFolderPath, strDest & "\" & strFileName, True

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39710471
When I tested it I got the attached.
script1.png
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39711062
Try this
Option Explicit
Dim strSource : strSource = "\\client\c$\barcode"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & "\" & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder strFolderPath, strDest & "\" & strFileName, True

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39711347
See attached.  I verified both paths and that the folders were shared for "everyone"  I'm not sure which path it can't find?

I also attached the screen shots of the paths.
script-path.png
barcode-path.png
barcode-path-on-local.png
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39711505
I don't see the path for
\\fileserver\community files\Public Files\Barcode
I just see
\\fileserver\community files\Public Files\
You need at least to create the folder Barcode in that directory.

If that still doesn't work, then try copying it to the same directory so you can see which one it can't find
objFSO.CopyFolder strFolderPath, strSource & "\" & "test.txt", True
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39711549
Agreed - seems the missing folder is what's triggering the error.
0
 

Author Comment

by:J.R. Sitman
ID: 39711768
See attached.  This is the screen shot from the Citrix connection that opens the Barcode folder.  

I'm confused on exactly what you want me to do to test?  
objFSO.CopyFolder strFolderPath, strSource & "\" & "test.txt", True
barcode-path2.png
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39711781
Okay, try this adjustment:

Option Explicit
Dim strSource : strSource = "\\client\c$\barcode"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & "\" & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
if not objFSO.FolderExists(strDest) then objFSO.CreateFolder(strDest)
objFSO.CopyFolder strFolderPath, strDest & "\" & strFileName, True

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39711811
I tried the new code (see attached), then I removed \Barcode from the path and got the same error attached.

I appreciate your patience with this.
barcode-path3.png
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39711843
So it looks like it is having trouble finding the local path.
Why are you using
Dim strSource : strSource = "\\client\c$\barcode"
instead of
Dim strSource : strSource = "C:\barcode"
?

Does this give the same error?
Option Explicit
Dim strSource : strSource = "\\client\c$\barcode"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & "\" & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
if not objFSO.FolderExists(strDest) then objFSO.CreateFolder(strDest)
objFSO.CopyFolder strFolderPath, strSource & "\" & "test.txt", True

Open in new window


Note: it will create a test.txt file in the same folder as the original if it works.

Also you could try using C:\
Option Explicit
Dim strSource : strSource = "C:\barcode"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & "\" & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
if not objFSO.FolderExists(strDest) then objFSO.CreateFolder(strDest)
objFSO.CopyFolder strFolderPath, strDest & "\" & strFileName, True

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39711915
I tried both.  Exact same error as in barcode path3.  The reason I was using the C$ was because the code I posted here was created by another EE and it works fine.

Could it be something in this line?

Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39711940
I doubt it's the file name - try this to see which is causing the error...it should give you a message indicating where the problem lies...

Option Explicit
Dim strSource : strSource = "\\client\c$\barcode"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & "\" & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

if objFSO.FolderExists(strSource) then  
  wscript.echo "Source path exists: " & strSource
else
  wscript.echo "Source path does not exist!"
end if
if objFSO.FolderExists(strDest) then  
  wscript.echo "Destination exists: " & strDest
else
  wscript.echo "Destination does not exist!"
end if
if objFSO.FolderExists(strFolderPath) then 
  wscript.echo "The file exists: " & strFolderPath
else
  wscript.echo "The file does not exist!"
end if


objFSO.CopyFolder strFolderPath, strDest & "\" & strFileName, True

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39711965
see attached
barcode-path-debug.png
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39711984
Ok, looking at the sample code a bit closer, it was set to copy a folder, not a file.
If that's what you're trying to do, then this should work...if not compare this output to the actual file name...

Option Explicit
Dim strSource : strSource = "\\client\c$\barcode"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & "\" & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

wscript.echo "Expecting to locate file: " & strFolderPath

if objFSO.FileExists(strFolderPath) Then
  objFSO.CopyFile strFolderPath, strDest, True
end if

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39711991
only want to copy "file"  

don't understand?  if not compare this output to the actual file name...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39712056
Ok, did you run it?  It should copy now since we're using the copyfile method...
0
 

Author Comment

by:J.R. Sitman
ID: 39712080
It stated expecting to locate file, then it got the attached error.  I increased the permissions on both locations to "everyone Full control"

Is there a way to find which location is having the permission error?
barcode-path-security.png
0
 

Author Comment

by:J.R. Sitman
ID: 39712112
Let's try coping the file to the folder pet-ark.  Please send code to do that.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39712115
share permissions or ntfs permissions?
if the share is everyone, full control, but the local/ntfs permissions deny write in any form, it will still fail.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 39712126
This version should work for you if it's not a permission problem.
I've added the trailing backslash, which was missing before...

Option Explicit
Dim strSource : strSource = "\\client\c$\barcode\"
Dim strDest : strDest = "\\fileserver\community files\Public Files\Barcode\" 
Dim strFileName : strFileName = "lb" & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Right(year(date),2) & ".txt"
Dim strFolderPath : strFolderPath = strSource & strFileName
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")

wscript.echo "Expecting to locate file: " & strFolderPath

if objFSO.FileExists(strFolderPath) Then
  objFSO.CopyFile strFolderPath, strDest, True
end if

Open in new window

0
 

Author Comment

by:J.R. Sitman
ID: 39712157
ntfs permissions are also set to Everyone full control.  New error.  see attached.
barcode-path-statement.png
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39712198
Your error indicates a problem with line 13...the version I posted only has 12 lines in it.
Did you add anything?
0
 

Author Comment

by:J.R. Sitman
ID: 39712212
Sorry there were two endif.  It's working.  Can we remove the message about the file it's looking for?  Don't need that, but if it's required, that's fine.

Thanks so much for sticking with this.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 39712216
Yeah, just take out the line that starts "wscript.echo ..." and it will be fine.
0
 

Author Comment

by:J.R. Sitman
ID: 39712224
PERFECT.
0
 

Author Closing Comment

by:J.R. Sitman
ID: 39712230
Thanks again.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39712520
Happy to help - thanx for the grade! :^)
0
 

Author Comment

by:J.R. Sitman
ID: 39712541
Thanks for your patience
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans
Suggested Courses

765 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