Link to home
Start Free TrialLog in
Avatar of J.R. Sitman
J.R. SitmanFlag for United States of America

asked on

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
Avatar of sirbounty
sirbounty
Flag of United States of America image

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

Avatar of J.R. Sitman

ASKER

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
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)
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

When I tested it I got the attached.
script1.png
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

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
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
Agreed - seems the missing folder is what's triggering the error.
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
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

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
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

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"
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

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

only want to copy "file"  

don't understand?  if not compare this output to the actual file name...
Ok, did you run it?  It should copy now since we're using the copyfile method...
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
Let's try coping the file to the folder pet-ark.  Please send code to do that.
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.
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ntfs permissions are also set to Everyone full control.  New error.  see attached.
barcode-path-statement.png
Your error indicates a problem with line 13...the version I posted only has 12 lines in it.
Did you add anything?
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.
Yeah, just take out the line that starts "wscript.echo ..." and it will be fine.
PERFECT.
Thanks again.
Happy to help - thanx for the grade! :^)
Thanks for your patience