Batch File to Copy a File to only folders beginning with certain letters

Hey guys,

I am not sure if this is possible.
We have a file that gets copied to users folders daily as the file is updated often.
The .bat file first deletes all the files in every folder on our E:\User Folders\ directory.

It then copied the file 1 by 1 to each folder.  Since the file is approx 200 mb, this takes a while and users that have their logon starting with a z for instance must wait a while for this file to get copied.  

We run this in the middle of the night so this woudl not be a big deal, however everyone once in a while, we make an urgent change and must push the file out during work hours.

We would like to be able to do this in stages... Possibly run the .bat file which will replace the file for users that start with for example A-F, then G-M, and so on.  This way users can work with the current version until the new one is copied over.

The current code is attached.

Any ideas or help would be greatly appreciated.
@echo.
FOR /R "E:\User Folders\" %%I IN (sdms*.*) DO del "%%I" /q   
FOR /R "E:|User Folders\" %%I IN (.) DO copy "E:\sdms.mdb" "%%I"
@echo.

Open in new window

LVL 1
schramm1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dcsdaveCommented:
Have you ever used robocopy?  It is a very fast copy utility and has a bunch of useful CMD switches.

I robocopy Quickbooks data files twice a day to our boss so that he can view live data and not change the main data.

Here is the link:

http://www.microsoft.com/Downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Take a look and if you have questions let me know.
0
schramm1Author Commented:
I have not used robocopy before.  

I will take a look and see if it helps.

Thanks for the quick response!
0
schramm1Author Commented:
Dave,

I downloaded robocopy and it seems like a very useful tool although I am not sure it will do what we need it to.  Maybe I am just missing the commands I need to use, but I cannot get this to copy to the subfolders of E:\User Folders\.  If you have any insight on how to do this with robocopy, please let me know.


Thanks
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

dcsdaveCommented:
If I remember right there can't be spaces in the folder names.  If there are just remember to use (" ").  I have a manual that has a great detailed description of the commands.  I will try to get you a link to it.  It might be included in the resource kit as a text or word doc if you want to see if you have it already  (I can't remember).

Also I was happier with the 1.7 version because it was all CMD line but the GUI version looks nice too.

I will get back to you on the manual.
0
dcsdaveCommented:
Here is the link to the "good" manual.

http://www.cleardigitalevidence.com/RoboCopy.pdf
0
AmazingTechCommented:
Under E:\User Folders directory I assume there are folders for your users. Are there subfolders underneath each users? If there are then the sdms.mdb file would be copied to several folders for each user.

I will assume you only have 1 subfolder deep under E:\User Folders.

The attached code would work similarily to what you code is doing except this one will limit doing A-F.

There's no reason why we couldn't delete and then immediately copy unless you wanted to make sure files are gone so the user is not tempted to go back in too early.

Here's a delete then copy for G-M

SETLOCAL ENABLEDELAYEDEXPANSION
@echo.
Set AlphaLow=G
Set AlphaHigh=M

FOR /F "tokens=* delims=" %%I in ('dir /ad /b "E:\User Folders\"') DO (
     Set UserFolder=%%I
     IF /I "!UserFolder:~0,1!" GEQ "%AlphaLow%" IF /I "!UserFolder:~0,1!" LEQ "%AlphaHigh%" (
          IF EXIST "E:\User Folders\%%I\sdms.mdb" del "E:\User Folders\%%I\sdms.mdb"
          copy "E:\sdms.mdb" "E:\User Folders\%%I"
    )
)

SETLOCAL ENABLEDELAYEDEXPANSION
@echo.
Set AlphaLow=A
Set AlphaHigh=F
 
FOR /F "tokens=* delims=" %%I in ('dir /ad /b "E:\User Folders\"') DO (
     Set UserFolder=%%I
     IF /I "!UserFolder:~0,1!" GEQ "%AlphaLow%" IF /I "!UserFolder:~0,1!" LEQ "%AlphaHigh%" IF EXIST "E:\User Folders\%%I\sdms.mdb" del "E:\User Folders\%%I\sdms.mdb"
)
 
FOR /F "tokens=* delims=" %%I in ('dir /ad /b "E:\User Folders\"') DO (
     Set UserFolder=%%I
     IF /I "!UserFolder:~0,1!" GEQ "%AlphaLow%" IF /I "!UserFolder:~0,1!" LEQ "%AlphaHigh%" copy "E:\sdms.mdb" "E:\User Folders\%%I"
)
@echo.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
schramm1Author Commented:
AmazingTech, you are correct with your assumption.   It is only 1 subfolder deep under E:\User Folders.

I also apoligize for the delay in my response.  This was more of a convenience to use then a necessity and we got very busy here.  This was the first chance I had to revisit this issue.

I just tested the batch file your created and it works perfectly!

Thank you so much for taking the time and effort to post that and again sorry for the delay!

Jeff
0
AmazingTechCommented:
Great. Thanks for the grade. I'm glad it worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.