Solved

Move files from directory to directory with .BAT-File

Posted on 2009-05-08
8
337 Views
Last Modified: 2012-05-06
Hi everyone,

I'm not that familiar with DOS and .BAT-Files. Thats the reason for this post. And i hope some one can help me solve this problem.

There is an Internet application where operators check check documents. Before that the operators check, the documents go trough 2 recognition engines. If the engines detect an ERROR they documents are placed in an map (maps or numbered from 1 to 200) in a special ERROR directory (see figure 1). The documents in the ERROR directory, must go back in the pipeline. I cant cut and paste, because that not efficient and there are parameters that need to be positive (see Figure 2). They have to be moved from ERROR to a special map into the input directory PDF. This map is also numbered from 1 to 200 (see Figure 3).

Parameters:
*User needs to give up an START and END date. Only the documents in that period need to be replaced.

*The minimum size of the documents. There or files of 0 Kb and those files need to stay in the error directory.

*Must give the amount that can be moved to a map into the PDF\1 map. For example the maximum of documents a map or 4000 documents. If the 4000 has been retched the next 4000 must bee moved to PDF\2 and so on.

*In a .TXT file must keep a log with the following information. Wich files have been copied and when.
Structure---ERROR-Directory.JPG
Documents-in-ERROR-Dir.JPG
Move-from-ERROR-dir-to-PDF.JPG
0
Comment
Question by:DonOetje
  • 3
  • 3
  • 2
8 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 24334738

@echo off
setlocal EnableDelayedExpansion
 
cd /D D:\Textkernel\Pipeline\xt_input
 
set /P dtstart=Start date in mm/dd/yyyy: 
set /P dtend=End date in mm/dd/yyyy: 
 
REM convert mm/dd/yyyy in yyyymmdd
set dtstart=%dtstart:~-4%%dtstart:~-10,2%%dtstart:~-7,2%
set dtend=%dtend:~-4%%dtend:~-10,2%%dtend:~-7,2%
 
set /P minsize=Minimum of size in Bytes: 
 
echo ---- from %dtstart% to %dtend%, size ^> %minsize% ---- >> logfile.txt
 
set cnt=0
set fld=1
for /F "tokens=*" %%F in ('dir *.pdf*') do if %%~zF GTR %minsize% (
  set dt=%%~tF
  set dt=!dt:~0,-6%
  set dt=!dt:~-4!!dt:~-10,2!!dt:~-7,2!
  if !dt! GEQ %dtstart% if !dt! LEQ %dtend% (
    set /A cnt+=1
    if !cnt! GTR 4000 set /A fld+=1& set cnt=0
    move %%F pdf\!fld!\
    echo %%F >>logfile.txt
  )
)

Open in new window

0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24334789
this is something that I did for another user.
http:Q_24330834.html#a24232677  --- Instructions for running it on a schedule.
http:Q_24330834.html#a24165351 --- Code here

This uses RoboCopy.

Good Luck
Carrzkiss
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24334816
Never mind my post.
It can probably do what you need, but not without a lot of work.
I hope that the information from: Qlemo:
Will do what you need, it looks like it will.

Good Luck
Carrzkiss
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:DonOetje
ID: 24334878
Qlemo: Thank you for your solution. Butt i have a question. Where do you set the ERROR and PDF directory. The files must be moved vroom ERROR to PDF.

In your script i see in line 4 the main directory. "cd /D D:\Textkernel\Pipeline\xt_input". In the for loop you give the wildcard *.pdf, this will search for all the docs in ERROR an in PDF. That is not suppose to happen.

Hope you understand what i mean.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24335517
I understand well. And you are partitially right, I forgot to use the ERROR folder. The code above will not do anything, as it will search in xt_input only, no subdirs.+
Replace line 19 with


for /F "tokens=*" %%F in ('dir *.pdf*') do if %%~zF GTR %minsize%

Open in new window

0
 
LVL 69

Accepted Solution

by:
Qlemo earned 50 total points
ID: 24335523
Sorry, paste error. Again:

for /F "tokens=*" %%F in ('dir ERROR\*.pdf*') do if %%~zF GTR %minsize%

Open in new window

0
 

Author Comment

by:DonOetje
ID: 24336087
Thank you very much! It works well! At least if the date is well converted. The date can be written in two ways. mm/dd/yyyy an dd-mm-yyyy. That one of the reasons it didn't work.

On Server 2003 the date will always be written like this: mm/dd/yyyy?

Qlemo thank you very much for your solution!
0
 

Author Closing Comment

by:DonOetje
ID: 31579362
Thank you for providing me a solution. I tested the script on a XP machine with the date set as dd-mm-yyyy, on the server the date is set as mm/dd/yyyy. I think that there must be a date check, to be sure that the right conversion will be used.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 129
Issues with Insert statement 12 29
Windows Services - Run a Program Grey Out 3 60
MS SQL + date 6 24
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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