How to create a batch file to copy PDF's from one drive to another drive on my server?

Posted on 2014-01-17
Last Modified: 2014-02-10
I created a batch file on my server to copy PDF's from the C drive to a mapped drive. However, it isn't working. When i change the mapped drive to the D drive (thats not a mapped drive), my script just doesn't work on a mapped drive. How do I get this to work so it will copy to my mapped drive? I read somewhere that if you move files to a mapped drive, the script needs to be a little different. Here's what i have:

@echo off
:: variables
set drive=F:\Quotes
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up directory...
%backupcmd% "C:\Program Files (x86)\QuoteHistory" "%drive%\%folder%"

How do I make this work to take the quotes from the C drive and make a copy onto the mapped F drive? Thanks!!!
Question by:brasiman
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
LVL 54

Expert Comment

by:Joe Winograd, EE MVE
ID: 39790022
Your script works fine on a mapped drive here – tried it on a mapped network drive and no problems. So it must be something related to your mapped drive or network or permissions. I see that you're using the /K option, which copies attributes. Maybe your mapped drive doesn't like that – try it without that option. Also, what happens if you manually issue the xcopy command in a command prompt? If it doesn't work in a normal command prompt, how about an elevated command prompt? Regards, Joe
LVL 30

Expert Comment

ID: 39790072
2nd the elevated command prompt.

Author Comment

ID: 39790696
Thanks Joe and pgm554 for your replies!

I will try taking out the /K. Good suggestion. I'm a rookie at this stuff. :)

As far as the elevated command prompt, how do you do that? I have this batch file, then have setup the Task Scheduler to run this once a week.
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

LVL 54

Expert Comment

by:Joe Winograd, EE MVE
ID: 39790722
Let's make sure that an elevated prompt solves the problem. To do this:

Start Menu
All Programs
Right-click on Command Prompt
Run as administrator

Let me know if that works and then I'll walk you through how to do it in Task Scheduler. Regards, Joe
LVL 54

Assisted Solution

by:Joe Winograd, EE MVE
Joe Winograd, EE MVE earned 250 total points
ID: 39791101
I haven't heard back from you and I'm going offline for a few hours, so here's how to run elevated in Task Scheduler. Someone set up the Task Scheduler to run your batch file once a week. So, run Task Scheduler. There are many ways to do's one:

Start Menu
All Programs
System Tools
Task Scheduler

You will see this in the upper left:

Task SchedulerClick the triangle pointed to by the red arrow above to expand the library. Keep clicking the triangles and clicking the libraries in the left pane until you see the task with your batch file in the top right pane. Then highlight that task and double-click it, which opens it for editing. You'll see something like this:

yourtaskTick the box that says [Run with highest privileges], as pointed to by the red arrow above (click OK to save the change). That will run the batch file elevated. I'll check back into this thread when I return in a few hours to see how you're doing. Regards, Joe
LVL 70

Accepted Solution

Qlemo earned 250 total points
ID: 39792325
Also note that you might not be able to rely on "F:" being available in the task (depends on a lot of factors). Try if using the UNC path \\server\share\... instead works.

Author Comment

ID: 39804751
I elevated the permissions and we will see if it works. I will try that shortly. Thanks!
LVL 54

Expert Comment

by:Joe Winograd, EE MVE
ID: 39804781
You're welcome! Looking forward to hearing your results.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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