Solved

Need help modify a script

Posted on 2013-12-10
31
379 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:jrsitman
  • 15
  • 12
  • 4
31 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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:jrsitman
Comment Utility
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
Comment Utility
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
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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:jrsitman
Comment Utility
When I tested it I got the attached.
script1.png
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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:jrsitman
Comment Utility
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
Comment Utility
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
Comment Utility
Agreed - seems the missing folder is what's triggering the error.
0
 

Author Comment

by:jrsitman
Comment Utility
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
Comment Utility
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:jrsitman
Comment Utility
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
Comment Utility
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:jrsitman
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:jrsitman
Comment Utility
see attached
barcode-path-debug.png
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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:jrsitman
Comment Utility
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
Comment Utility
Ok, did you run it?  It should copy now since we're using the copyfile method...
0
 

Author Comment

by:jrsitman
Comment Utility
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:jrsitman
Comment Utility
Let's try coping the file to the folder pet-ark.  Please send code to do that.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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 500 total points
Comment Utility
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:jrsitman
Comment Utility
ntfs permissions are also set to Everyone full control.  New error.  see attached.
barcode-path-statement.png
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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:jrsitman
Comment Utility
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
Comment Utility
Yeah, just take out the line that starts "wscript.echo ..." and it will be fine.
0
 

Author Comment

by:jrsitman
Comment Utility
PERFECT.
0
 

Author Closing Comment

by:jrsitman
Comment Utility
Thanks again.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Happy to help - thanx for the grade! :^)
0
 

Author Comment

by:jrsitman
Comment Utility
Thanks for your patience
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now