• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • Last Modified:

Need help modify a script

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
J.R. Sitman
Asked:
J.R. Sitman
  • 15
  • 12
  • 4
1 Solution
 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
TommySzalapskiCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
When I tested it I got the attached.
script1.png
0
 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
TommySzalapskiCommented:
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
 
sirbountyCommented:
Agreed - seems the missing folder is what's triggering the error.
0
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
TommySzalapskiCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
see attached
barcode-path-debug.png
0
 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
only want to copy "file"  

don't understand?  if not compare this output to the actual file name...
0
 
sirbountyCommented:
Ok, did you run it?  It should copy now since we're using the copyfile method...
0
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
Let's try coping the file to the folder pet-ark.  Please send code to do that.
0
 
sirbountyCommented:
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
 
sirbountyCommented:
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
 
J.R. SitmanIT DirectorAuthor Commented:
ntfs permissions are also set to Everyone full control.  New error.  see attached.
barcode-path-statement.png
0
 
sirbountyCommented:
Your error indicates a problem with line 13...the version I posted only has 12 lines in it.
Did you add anything?
0
 
J.R. SitmanIT DirectorAuthor Commented:
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
 
TommySzalapskiCommented:
Yeah, just take out the line that starts "wscript.echo ..." and it will be fine.
0
 
J.R. SitmanIT DirectorAuthor Commented:
PERFECT.
0
 
J.R. SitmanIT DirectorAuthor Commented:
Thanks again.
0
 
sirbountyCommented:
Happy to help - thanx for the grade! :^)
0
 
J.R. SitmanIT DirectorAuthor Commented:
Thanks for your patience
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 15
  • 12
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now