Need batch file to move multiple files to subdirectory?

Posted on 2010-01-06
Last Modified: 2012-05-08
Below is where I'm at trying to figure out how to move the defrag log, then copying the log file and adding the date to the new file name, then moving new file and any file with "defrag_" in the name to a subdirectory on the local system. Then I would like to copy this folder to a folder on the server. But I can't figure out the syntax of the move or whatever command I should use to accomplish this task.

defrag c: /v /f >defrag_c.log
copy defrag_c.log defrag_c_%date:~10,4%-%date:~4,2%-%date:~7,2%.log


This is what I thought I should do: defrag_c.log is located in c:\dir1\dir2

defrag c: /v /f >defrag_c.log
copy defrag_c.log \\server1\dir1\dir2\defrag_c_%date:~10,4%-%date:~4,2%-%date:~7,2%.log
defrag c: /v /f >defrag_c.log
copy defrag_c.log defrag_c_%date:~10,4%-%date:~4,2%-%date:~7,2%.log
copy defrag_*.log to c:\ dir1\dir2\dir3
xcopy c:\dir1\dir2\dir3 \\server1\dir1\dir2
move defrag_*.log to c:\dir1\dir2\dir3
xcopy c:\dir1\dir2\dir3 \\server1\dir1\dir2

Thought I tried every combination but they failed.

This batch file that can copy a folder to a specific location on a server, weekly, can help in a lot of ways to ease the routine maintenance grind. Thanks.

Question by:FrankU09
    LVL 7

    Accepted Solution

    can you please tell where you are failing if it is failing at the stage of copying to the shared location you can probably add the shared location as a drive and then do a xcopy

    net use x:  \\server1\dir1\dir2
    xcopy /y   c:\dir1\dir2\dir3 x:

    Author Comment

    It fails during the move or copy to subfolder on local system.
    LVL 7

    Expert Comment

    what does it tell ie any error message??

    Author Closing Comment

    The net use helped. I also noticed that running the batch file remotely using RUN > \\workstation1\c$, you get an error about UNC not supported, reverting to Windows ???. So, I used RDP to run batch and test and it all worked. Thanks.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
    A quick step-by-step overview of installing and configuring Carbonite Server Backup.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now