Solved

Batch (.bat) file to  copy files from one folder to another

Posted on 2015-02-09
6
282 Views
Last Modified: 2015-02-21
Hi ,

      I have two folders  - SourceFold  and  DestFold    

      There are several  sets of Files in the sourceFold  (each set has two files in it -   For ex.  1.dgn , 1.txt   )

       So a sample  folder will have  something like  1.dgn , 1.txt  , 2.dgn , 2.txt , 3.dgn, 3.txt  .........

      I need the following batch file

         cut/copy  a set (for example 1.dgn, 1.txt)  from  SourceFold  and copy to DestFold
            ( Important: Make sure  the  ,dgn file is copied first and then the .txt file )

          wait till the Destfolder is empty  ( with some internal process , the copied files will be absorbed .Wait till that)
         
          cut/copy  next set  

           ....   and it goes on  till last set

       can you please help with this Batch File ?

  Thanks in advance
0
Comment
Question by:Sam OZ
6 Comments
 
LVL 3

Expert Comment

by:Shane Kahkola
ID: 40600033
The only thing I know you can use in a batch file that can "monitor" a folder is Robocopy.  If you do it right, you can make Robocopy monitor the SourceFold and copy all sets to the DestFold whenver there is a change in the files.  It can also inspect the file to determine if it is different from an existing file in the destination.

I have attached the help file for Robocopy, but can you tell me a bit more about the context of this file?  What is your overall goal?
robohelp.txt
0
 

Author Comment

by:Sam OZ
ID: 40600058
Hi ,

    Thanks .
             The files are in sets ( 1.dgn, 1.txt , 2.dgn,2.txt ... )    kept in Source folder
             The overall goal is to  copy  files - one set at a time -  from Source folder to Dest folder .              
             But there are two rules to impose
      My key requirement is that  
       1)  the .dgn file  should be copied first and then .txt file  
        2) Copy the next set  only after the current set is sucked out by some internal  process (In other words,  only when the Dest Folder is empty)
0
 
LVL 3

Expert Comment

by:Shane Kahkola
ID: 40600077
In this case, I would recommend a scheduled task that will inspect the destination folder to see if it has files.  If not, you can copy the next set from the source folder.  

I'm not real good with batch file "for" loops, but that's essentially what you want.  Here's an explanation of how the for loop works in batch files:
http://ss64.com/nt/for.html

I'm willing to help you put one together, but I don't have time tonight.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40600109
why a batch file, anyhow, if you are posting in Microsoft development?
I would make this a Service to run in windows, to check in intervals and/or with foldernotification events, not even a scheduled service...
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40600201
@Guy: I think the OP may have been unsure of the categories to use.
0
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
ID: 40600216
- Moves numerically named .dgn & .txt file pairs.
- Files are named 1.dgn, 1.txt, 2.dgn, 2.txt, etc.
- Next pair cannot be moved until prior pair is removed.
- Sends results to a log file
- Revise SrcD, DstD, and FNLog folder names to fit your needs
- Copy the code below and save to a file such as MoveFilePairs.bat. I put my files in c:\utils. Adjust the folder name to your taste
- Confirm that it works via a test run of MoveFilePairs.bat in a CMD window.
- To run this on a recurring basis, use Task Scheduler.
-- Set a Trigger per your time frequency.
-- For Action:
--- Program: cmd
--- Add arguments: /c c:\utils\MoveFilePairs.bat
@echo Off
SETLOCAL ENABLEDELAYEDEXPANSION
set SrcD=c:\utils\Source
set DstD=c:\utils\Dest
set FNLog=c:\utils\%~n0.txt
for %%A in (%SrcD%\*.dgn) do (
  set FN=%%~nA
  set Ext=%%~xA
  set /a FNLast=!FN!-1
  if exist %DstD%\!FNLast!!Ext! (
    echo Can't move %SrcD%\!FN!.* till %DstD%\!FNLast!!Ext! is removed
    echo %date% %time% Can't move %SrcD%\!FN!.* till %DstD%\!FNLast!.* is removed>>%FNLog%
    exit /b
  ) else (
    for %%B in (!FN!.dgn !FN!.txt) do call :MoveIt %%B
    exit /b
  )
)
echo Done %0
popd
goto :eof

:MoveIt
move %SrcD%\%1 %DstD%>nul
if %errorlevel% equ 0 (
  echo Moved %SrcD%\%1 to %DstD%
  echo %date% %time% Moved %SrcD%\%1 to %DstD%>>%FNLog%
) else (
  echo Error moving %SrcD%\%1 to %DstD%
  echo %date% %time% Error moving %SrcD%\%1 to %DstD%>>%FNLog%
)

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

760 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

20 Experts available now in Live!

Get 1:1 Help Now