Batch file monitor copy to 2nd PC then move

April 22, 2010 at 20:45:45
Specs: Windows XP, 4000+ / 2gb

I Need help to make a batch file, I have some basic knowledge but nothing much with variables.

Here is just a sample of the millions of files I have to deal with, we have new scenery tiles for a G.P.L. open source simulator and I need to make a scenery file directory database for one, based on tile location. This is just a small sample of the work I have to sort through.
http://ftp.linux.kiev.ua/pub/fgfs/S...

SCHEDULED FILE SYNCHRONISER
1/ I have a scheduled download application on Computer #1, Windows 2000 it stores all files in X:\downloads folder, once download is completed it moves the files to another sub-folder called X:\Downloads\complete (Where X means it might be changed to suit my needs)

2/ Other PC's on the network are not always active so this move cannot be done by this application over the L.A.N. When a download is complete when other PC#2 is off-line it needs to wait, Computer #1 is active 24/7/365 and is the main server pc and the files are only kept temporarily there!

3/ The files are a mixture of types and names and must be sorted by name & type into pre-defined folders on PC#2

******** FIRST THE BATCH FILE REQUIREMENTS PC#1 ***********
Batch file PROGRAM must monitor for new files that exist in X:\Downloads\complete

Or run on a schedule every 30 minutes, When new files are found it checks to see if remote PC#2 is on the network If TRUE, AND IF FILES NOT COPIED BEFORE OR UNDER 1 HOURS OLD BY CREATION DATE THEN IT copies the files to X2:\unsorted (X2 being the remote network drive such - as J:\ etc.) ON PC#2

IF PC#2 is off-line THEN it needs to remember, or wait for PC#2 to come up, AND ALLOW 10 Minutes to elapse before copying files over to prevent any system problems during boot stabilisation time. (I'm sorry if this seems a challenge but it's driving me crazy .... Can it be done even ?)

The files must only be copied over once perhaps a log file can be stored on local PC#1 or remote PC#2 that it Store's/reads chk-sum history ? at X2:\unsorted\history.log as a hidden file? then even after the files in X2:\unsorted have been moved and sorted to their correct folders such as folder abc, folder jkl, etc the exact same file names or checksums of the files will verify they have already be done.

******** THE BATCH FILE REQUIREMENTS PC#2 *************
I actually have a basic batch file for doing this sorting, the problem I have is after sorting the files and moving them from X2:\unsorted the batch file on PC#1 re-copies them again and this complicates things as it over writes the files over and over and it's clogging my network unnecessarily. If a simpler batch can be made that is not as bulky as mine for the sorting by abc*.doc def*.zip *.tgz can be made it would be much appreciated I have been struggling with this for days.

I hope I have not been too detailed just wanted to save time, by their being no misunderstanding.

All the best Michelle


See More: Batch file monitor copy to 2nd PC then move

Report •


#1
April 22, 2010 at 22:30:24

my approach would be to streamline as much as possible. One way might be to have pc#2 send a flag to the server when it has done with boot-up, instead of having the server have to act as a 30-minute timer (wasteful and infefficient).
Server looks for pc2 online, then looks for flag. if not both, sit back and wait. pc2 boot-up (what i still think of as autoexec.bat) would have, as last instruction, to send flag (incl. time & date to be verified on server.)
Another way might be to have the server do the sorting of the files into directories, on its own local drive, then use xcopy /s to recreate them on pc#2, eliminating need for the reciever-batfile on #2.
Another, to prevent duplication of copying to use the "A" attribute to flag (and unflag) files as "need to copy" or not. xcopy /M will copy only "A" tagged files and untag them as they are copied, so they won't be candidates for copying the next go-round.
Although obviously not a turn-key solution, maybe points to things to consider.
Also, if you have existing script, might help to post it.

Report •

#2
April 23, 2010 at 03:17:15

I will take me a while to get through this, but at firat glance it's about monitoring for file changes/copies which is a problem in batch. Maybe a VBS is better suited. Three are helpers here who are good with VBS.

I'll look it over.


=====================================
Helping others achieve escape felicity

M2


Report •

#3
April 23, 2010 at 04:49:59

Question regarding server (computer 1) which checks client (computer 2):

If only actions can be done, after the client is up for consecutive minutes, this is what you can do (in pseudo code):

-set sounter to 0
-start loop
-check if client is available
-if available, add 1 to counter
-if not available, set counter to 0
-if counter is 10 or higher, exit this loop
-sleep 1 minute
-otherwise (counter less than 10) go to begin loop
-perform action which can only be done with client up and running


Note that this is a check performed from the server, and that it requires nothing special on the client (apart from having an IP address). Although this is interesting, the above check is not good if the client (computer 2) is already running (for hours) cause it will take 10 minutes to say : yes, it's up for 10 minutes.

A better method, may be that the client is aware how long it is running. There are many ways to do this, and then let the server check this data. He could then read : client is up for 7 minutes, I need to wait. Or, client is up for 2 hours+, all OK.


Report •

Related Solutions

#4
April 23, 2010 at 05:04:58

For your copy needs, pls check if XCOPY /D is not sufficient. This will copy any non-existing or older target file. You dont have the check regarding 1 hour or more, but this is much simplier, and maybe it already suits.

Problems can occur with large files that often change dates (like databases, VMware images, etc.) because XCOPY only checks dates, and needs to copy complete files. But, if you have small files, it doesn't matter if there are lots or not, it'll go fast.


Report •

#5
April 24, 2010 at 09:58:48

Some of these files are large yes I work with images, one of the problems with scenery tiles is disk fragmentation they are a huge problem when their are millions of them so part of what I do is build new scenery iso images to take the fragmentation problem away from the hard disk.

Currently I am building NEW world scenery version (2.00) Sorry that was a typo just realised, meant v1.0.1 ,any users downloaded the free scenery before on tor which I made to take burden of the main servers mostly for windows users. Of coarse I work with other files too such as zip, avi, png, jpg, etc as I make my own movies from scratch so I need to be able to sort all types in one application.

A lot of what I do is to make scenery iso images.... around 4GB

http://www.flightgear.org/Downloads...

Oh I just re-read a post above, PC#1 is mostly good for downloading but it has very poor processing power sorting and moving files is rather sluggish and disk space limited, where the pc#2 has a 4000+ cpu and a very fast hard drive this is why I chose sorting there, plus to sort on pc#1 also means more mapped drives or folders as on pc#2 many files are on different partitions.

Michelle


Report •

#6
April 24, 2010 at 11:31:31

This is a short section of my sort batch file for PC#2 needless to say it's only part built as I got frustrated with the fact it was copying twice some files that PC#1 I resent over the LAN, , and I'm not that good with making batch files :( unfortunately I'm clueless about some of the stuff to do with xcopy never used it!

wizmo by the way is a little program I use in my batch files from here http://www.grc.com/wizmo/wizmo.htm

Michelle

***********************************************************************
@echo off
g:
cd\data-mig\Migrate
if not exist *.tgz goto none

if exist w18*.tgz copy w18*.tgz "I:\scenery\w18\*.tgz"
echo Scenery tile copied
if exist w18*.tgz del w18*.tgz
echo.

:3
if exist w17*.tgz copy w17*.tgz "I:\scenery\w17\*.tgz"
echo Scenery tile copied
if exist w17*.tgz del w17*.tgz
echo.

:4
if exist w16*.tgz copy w16*.tgz "I:\scenery\w16\*.tgz"
echo Scenery tile copied
if exist w16*.tgz del w16*.tgz
echo.

:5
if exist w15*.tgz copy w15*.tgz "I:\scenery\w15\*.tgz"
echo Scenery tile copied
if exist w15*.tgz del w15*.tgz
echo.

:6
if exist w14*.tgz copy w14*.tgz "I:\scenery\w14\*.tgz"
echo Scenery tile copied
if exist w14*.tgz del w14*.tgz
echo.

:7
if exist w13*.tgz copy w13*.tgz "I:\scenery\w13\*.tgz"
echo Scenery tile copied
if exist w13*.tgz del w13*.tgz
echo.

:8
if exist w12*.tgz copy w12*.tgz "I:\scenery\w12\*.tgz"
echo Scenery tile copied
if exist w12*.tgz del w12*.tgz
echo.

echo ALL REMAINING
:9
if exist *.tgz copy *.tgz "I:\scenery\unsort\*.tgz"
echo All Remaining Files Copied These still need sorting
if exist *.tgz del *.tgz
echo.

:10


rem ------------------------- ADD MORE COMMANDS HERE -------------------------
echo ALL FILES HAVE BEEN MOVED ...
e:
cd\"System\Audio Alerting"
start wizmo.exe play=all_done.wav volume=50"
pause
cls
goto end

:none
echo Sorry no file's were found to move!
e:
cd\"System\Audio Alerting"
start wizmo.exe play=oops.wav volume=50"
pause
cls
:end
exit

...........


***********************************************************************


Report •

#7
April 24, 2010 at 15:19:04

You guys are amazing, I have re-written my batch files using xcopy thank you nbrane and tvc it does seem to do the trick for most of the work, but perhaps I should have mentioned earlier I am a bit of a disk optimisation geek :op my 500GB drive is a nightmare to defrag and it's mostly used for serving data over ftp and scenery iso via my simulator, and can take hours to defrag, so what I usually do to speed things up is copy files from PC#1 to a different physical drive (files fragmented) and as the data flow is slow it always ends up fragmented to hell, then on my fast PC#2 I move those files to the FAST sata drive which as it is a separate physical drive the head has little jumping around to do. so all the files created there are contingent perhaps I should have mentioned this :)

As regards the "pseudo code" erm you completely lost me there ? I don't know much at all but what ever it does it sounds usefull you wrote "-set sounter to 0
-start loop
-check if client is available
-if available, add 1 to counter
-if not available, set counter to 0
-if counter is 10 or higher, exit this loop
-sleep 1 minute
-otherwise (counter less than 10) go to begin loop
-perform action which can only be done with client up and running"

Yes that would help with the boot time if someone could write me a simple script for this that can run my batch file if PC#2 is online 10 minutes that would be great, it does not need to be all in one just a trigger script to run a batch would be great :)

I DO PREFER having the sort function on the PC#2 as this is the machine I work on most of the time and PC#1 is mostly a slave server for autonomous tasks. Most research, and editing, and scenery work is on PC#2.

Application!
May I just say this is a long term solution I need as the project is growing enormous and their are hundreds of aircraft models also over 333 in CVS and many more outside the CVS system, and many of these can get scattered all over my disk over several years of downloading I have not been the best in disk keeping on my older server it gets neglected a bit :( so this batch would aid me a great deal in current and future re-organisation :)

More info.
The scenery tiles are for the whole planet earth, and use GPS way point addresses each top level tile might be a hundred miles square, then in the sub folders you may have millions more small files that sometimes I have to find a small stg file and remove it or sort / edit it I think you get the idea :) I do use a directory exam-diff program but this is not always helpful at least in re-ordering files by name*type, as it gets over loaded as their are too many to sort.

The aircraft alone come to 333 models in CVS alone.

Again your all amazing,
Michelle


Report •

#8
April 24, 2010 at 15:32:49

oops! we crossed in the mail! (that happens a lot to me)

ok, here's my feeble strategy:
first question, though, what drives the downloader to move
the files to the complete directory? a batchscript or a exe?
because if it's a script, or something that you can manipulate, then that would make it easy to do the rest.
so for now, i'll assume it is something that can trigger the whole of the following chain
downloader-server (the slow guy, pc#1):
after moving the files to \complete:
:download
:: this is the routine that is downloading the files into
:: the temporary-storage before moveing them to "complete"
ftp -s ftpscrpt
:: at this point, let's assume that the files are ready to move:
move *.* .\complete
:now check pc2 status
for /f %%a in ('ping pc#2 ^|find "Reply"') do (
:: the pc2 is not there, so remove the status flag
if errorlevel 1 (
del statflag
goto :download
) else (
:: pc2 is online, but might not be "stabilized" yet, the statflag,
:: which is created by pc2 after boot-up and 10-minute wait,
:: indicates whether the pc2 is ready for receiving
:: at this point, you can do one of two here on pc1: wait on pc
:: 2 (ten minutes tops), or resume download pending the next
:: "completion": here is the 2nd option:
if not exist statflag goto :download
:: here is the first option:
:testflag
:sleep 30 seconds to keep from wasting system resources
sleep 30
if not exist statflag goto :testflag
:: now pc2 is ready for delivery. The xcopy uses the archive-bit
:: to determine if the files have already been transferred.
:: note that the "newer-than-date+time" option won't work due
:: to pc2 moving the files out of the incoming directory.
xcopy /m .\complete\*.* \\pc2\incoming
:: now, as the last item, send an "i'm done" flag to pc2
echo ok > \\pc2\incoming\statflag
goto :download
:: --------- end of pc1 script: resume the download stuff.

pc2 script:
boot-up sequence (hklm\software\microsoft\windows\currentversion\run)
flag.bat:
:: sleep 10 minutes then set the ok-flag on pc1
start /w sleep 600
echo ok > \\pc1\statflag
start lookfor.bat
:: ---- end boot-up script
lookfor.bat:
:: this is basically your sort-script, but optimized somewhat
@echo off
:beginagin
for /L %%b in (18 -1 12) do move /y w%%b*.tgz "I:\scenery\w%%b\*.tgz"
move /y *.tgz "I:\scenery\unsort\*.tgz"
:: remove the current "ready" flag
del statflag
:now do similar to pc1: keep testing for new data ready
:testflag
sleep 30
if not exist statflag goto :testflag
goto :beginagin
::------- end
there's too much i don't know about your setup to be much more specific than this, (even with your detailed description),
at least at this point. It's a fairly elaborate series of steps,
and both pcs need to be running scripts that follow an agreed-upon protocol to keep things in sync.
The xcopy /M is the most critical command, because that is what will keep the files from being copied over and over.
On the other hand, if you don't need the files to remain on pc1, you could just move them instead of copy, then there won't be any files to move after the move!


Report •

#9
April 24, 2010 at 16:55:49

Dear nbrane, that looks amazing I will test it out asap I am kind of tired now, and thank you so much for your work here, it's after midnight but hopefully will be able to get this working sometime tomorrow :) BTW I use Get-right 6.3e it is an application, it has a very basic "Run a program or command:" When Done Notification I use this to run a batch file copy then delete command so it is not exactly a be all solution!

it does trigger batch files though :)
will get back if any problems ...

Michelle


Report •

#10
April 24, 2010 at 18:22:51

here's a "sleep.com" i wrote, generated by the following batchfile, but they're easy to find for downloads online:
@goto :aa
E100 BE 81 00 AC 3C 0D 75 FB 81 FE 82 00 74 3E BA 01
E110 00 4E 4E 81 FE 81 00 74 15 B4 00 8A 04 2C 30 52
E120 F7 E2 01 C3 B8 0A 00 5A F7 E2 89 C2 EB E4 53 B4
E130 2C CD 21 88 F7 CD 21 38 F7 74 FA B4 0B CD 21 B2
E140 2A B4 02 CD 21 5B 4B 83 FB 00 75 E2 B4 4C CD 21
rcx
50
nsleep.com
w
q
:aa
@echo off
debug sleep.com < %0.bat
echo demonstrating sleep.com...
echo sleeping 10 (seconds) - (ctrl-c aborts)
sleep 10

Report •

#11
April 25, 2010 at 09:37:53

Hi nbrane,

Pretty neat. I'm trying to figure out how to lose the error caused by @goto in debug.

No luck.

I like the row of stars.


=====================================
Helping others achieve escape felicity

M2


Report •

#12
April 25, 2010 at 11:47:18

Lol! yeah, i thought about taking those out but didn't have the heart - i made the original (including the stars) about 15 years ago...
and yeah, one could always make a second file to get rid of the error, but i think that's even more messy than >nul 2>1, especially since it only needs to run one time, pretty much.

Report •

#13
April 25, 2010 at 19:55:08

Hi guys this all looks great, however this is quite complicated to my old brain, at 50 I'm not as fast these days, so I need some time to digest it out and put this all together, here, as even simple batch files give me a head ache and I just realised my example batch had errors in it and I'm always making typos :/

I was getting weird things happen with my audio alerts then realised the start wizmo.exe play=oops.wav volume=50"
had the " at the end and have no idea why it's there, so removed it then had wizmo path errors saying wizmo could not be found? I thought eh what? so had to re-establish the path to it, with F: on (PC#1) it uses another type of batch I found on these forums and changed a week or so ago but is not ideal, I need audio alerting because lets say the Batch file starts copying files on PC#1 and I am just starting to shut-down PC#2 well ? perhaps PC#1 is going to throw a fit or something with a nasty network unavailable error OOPS never thought of that! So Audio alerts are very important in this case which is why I use wizmo, sorry not had time to put this all together yet need some time or any other ideas about a fail safe if the network goes off-line halfway through a copy ?

This is what I WAS trying out before on PC#1 it sort of works but has problems.

I have not added the DEL *.* to this batch simply because I do not trust it fully.

OK now I need to start using the new coding you guys came up with :) /me trembles at the thought of integrating this lol

Michelle

::===
@echo off
rem ---------------------- Copy 1 sub directory --------------------------
if not exist W:\* goto error
cls
echo Downloading Main Files !
start wizmo.exe play=switching.wav volume=50
setLocal EnableDelayedExpansion
if not exist %TEMP%\# type nul > %TEMP%\#
pushd I:\Downloads\complete
for /f "tokens=* delims= " %%a in ('dir/b/a-d /s') do (
find "%%a" < %TEMP%\# > nul
if errorlevel 1 xcopy /d /s /m /f %%a W:\Migrate\*
)
dir/b/a-d > %TEMP%\#

rem --------------- End Move 1 sub directory --------------------------

echo Files Have Been Copied to PC#2
F:
rem does not work properly when multiple wismo are used
rem start wizmo.exe play=done2.wav volume=50
echo Done

rem ---------------------- Copy 2 sub directory --------------------------
:move2
cls
rem got this code from http://www.computing.net
rem NOT ALL FILES DOWNLOADED CAN BE MOVED SUCH AS BROWSER DOWNLOADS
rem This is a check for other files that might need moving, but aborts if partial or temp files present
echo Next Batch of Files being Moved is fgrun+fgfs-osg-win32-cvs-201*.zip
if not exist "I:\Downloads\fgrun+fgfs-osg-win32-cvs-20*.zip" goto nofile
if exist "I:\Downloads\*.!ut" goto nofile
if exist "I:\Downloads\*~*" goto nofile
if exist "I:\Downloads\*tmp*" goto nofile
setLocal EnableDelayedExpansion
if not exist %TEMP%\# type nul > %TEMP%\#
pushd "I:\Downloads\*"
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
find "%%a" < %TEMP%\# > nul
if errorlevel 1 xcopy /d /s /m /f %%a W:\Migrate\*
)
dir/b/a-d > %TEMP%\#

rem -----------------------------------------------------------------------

:alldone
rem be usefull to have a delayed exit to give time to read if user present !
echo Files Have Been Copied to Venus 6
F:
rem start wizmo.exe play=done2.wav volume=50
echo Done
goto exit

:nofile
echo Their are no suitable candidates in that directory, or partials are present
F:
start wizmo.exe play=oops.wav volume=50
goto exit

:error
echo That Computer Appears to Be Offline!
F:
rem start wizmo.exe play=error.wav volume=50
:exit


Report •

#14
April 25, 2010 at 20:12:50

I don't seem to have a sleep.com file ? i get an error in the cmd window I'm on windows 2000 and XP is it an extra program I need ?

Those binary numbers got me stumped Oo

OK looking at the code is the
\pc2\incoming\ (my actual path ?)
if so pc2 = machine name / IP address ?
and incoming = my directory / folder ? (yes/No)

Michelle


Report •

#15
April 25, 2010 at 20:21:49

Michelle,

The batch he posted creates the SLEEP.COM

And yes, there's an error; non-critical.

It still creates the SLEEP. 80 bytes


=====================================
Helping others achieve escape felicity

M2


Report •

#16
April 25, 2010 at 20:49:49

OH wow that's amazing he can do that :) so I make a batch for sleep.com or just put that code inside the batch file ?

OK I got the sleep.com working pretty neat :D
I put a copy of it in my windows command folder, but I guess it's best to keep a copy with the batch to save path problems.


Report •

#17
April 25, 2010 at 20:54:06

Put this in MY.BAT

========================

@goto :aa
E100 BE 81 00 AC 3C 0D 75 FB 81 FE 82 00 74 3E BA 01
E110 00 4E 4E 81 FE 81 00 74 15 B4 00 8A 04 2C 30 52
E120 F7 E2 01 C3 B8 0A 00 5A F7 E2 89 C2 EB E4 53 B4
E130 2C CD 21 88 F7 CD 21 38 F7 74 FA B4 0B CD 21 B2
E140 2A B4 02 CD 21 5B 4B 83 FB 00 75 E2 B4 4C CD 21
rcx
50
n sleep.com
w
q
:aa
debug < %0.bat


=====================================
Helping others achieve escape felicity

M2


Report •

#18
April 25, 2010 at 20:55:12

i "checked my work" - cut/pasted the script into sleeptst.bat
and ran it. cut/paste everything from the "@goto" down.
my screen looked like this when i executed the batchscript:
C:\>sleeptst
File not found

-@goto :aa
^ Error
-E100 BE 81 00 AC 3C 0D 75 FB 81 FE 82 00 74 3E BA 01
-E110 00 4E 4E 81 FE 81 00 74 15 B4 00 8A 04 2C 30 52
-E120 F7 E2 01 C3 B8 0A 00 5A F7 E2 89 C2 EB E4 53 B4
-E130 2C CD 21 88 F7 CD 21 38 F7 74 FA B4 0B CD 21 B2
-E140 2A B4 02 CD 21 5B 4B 83 FB 00 75 E2 B4 4C CD 21
-rcx
CX 0000
:50
-nsleep.com
-w
Writing 00050 bytes
-q
demonstrating sleep.com...
sleeping 10 (seconds) - (ctrl-c aborts)
**********C:\>
:::::---------::::::: end screen-shot :::::---------:::::::
the error message(s) are normal byproduct.
sleep.com should be functional in the demo...
(maximum 65535 seconds)
If you can't get it working, you can use choice or ping
to generate a delay:
ping -n 1 -w 600000 0.0.0.127
or:
choice.exe /t:y,600
(both examples for 10-minute delays)


Report •

#19
April 25, 2010 at 21:12:48

Yeah it works and if I edit the shortcut with
C:\WINDOWS\COMMAND\sleep.com 20
it counts to 20 no problem :)

Oh one down now to finish the main batch files, I get a little confused with the text starting with :: but I guess thats the same as REM comments so I get that.

just copying stuff over now to my new batch bit by bit lol :)

michelle


Report •

#20
April 25, 2010 at 21:57:25

I am just trying to work out where this goes ?
boot-up sequence (hklm\software\microsoft\windows\currentversion\run)
flag.bat:

Do I have to start flag.bat at boot time or can it just be run for the start menu ? or Task Scheduler ?

Of coarse if it can be added to my start up registry that's fine by me but I am not sure where ....

I figured it out the hklm was just different on my system in registry editor was able to create a new key and string so that should do that, their was another thing I need.

for some files that are copied over such as abcd I want them to be put in their own folder created by a partial of the file-name so I can maintain better ordering so if files are moved on PC#2 to a folder called "I:\scenery\" and the first part of the file name is w12 then all files that begin w12 are stored in a folder by that name! If folder already exists then I don't want it over written!

PLUS is it possible (in flag.bat) to have a check for disk LOCK Drives G: & I: or any for that matter ? such as when running a defrag on PC#2 ? or PC#1 ?

Michelle


Report •

#21
April 26, 2010 at 00:13:29

the critical issue is how you determine "files that begin with",
ie: delimited vs positional (absolute position/length).
f/e: w12 is either the first 3 char.s, or the next two after the "w", or none-of-the-above. there's always a way, it's just a matter of pattern-matching...if you can give filename format...
ps: i used to waste hours "playing" flightsim, tough landing those learjets on the aircraft carriers, (hop and drop)!

Report •

#22
April 26, 2010 at 01:13:50

Hi nbrane, :) well you certainly know your stuff, its great to know you like flightsims as im actually talking about flightgear above with the scenery, I am not one of the DEVS I just make movies based on it and try to help out a bit with the windows mountable scenery DVD's, anyway back to the batch, I am playing around with the code you gave me to see if I can get it to move other files as I was thinking how much of a mess my other computer is in with files all over the place it will be nice to even sort all the files on the PC#1 too sometime!

But having edited and changed the script to do the entire alphabet what actually determines the path here, and does it support multiple file extension masks such as *.doc *.pdf *.txt ?

Sorry my extra bits are making it wrap to window and harder to follow so have removed some masks, and shortened the file path for clarity.

for /L %%b in (18 -1 12) do move /y a%%b*.doc *.pdf "I:\Docs\a%%b\*.doc *.pdf"
for /L %%b in (18 -1 12) do move /y b%%b*.doc *.pdf "I:\Docs\b%%b\*.doc *.pdf"
for /L %%b in (18 -1 12) do move /y c%%b*.doc *.pdf "I:\Docs\c%%b\*.doc *.pdf"

Again this is a snippet have not tried it yet as I'm scared it might do something nasty if I got the paths wrong !!!

All the file names are fairly unique, in that the scenery tiles are geological w=west and e=east then theirs the numbers which are co-ordinates such as w130n30 = west130 Degrees & North 30 Degrees so fairly unique and predictable.

Going into deeper levels they are often co-ordinates within a tile, so several tiles might share similar co-ordinates, the only thing that makes them unique is the top level tile (folder) such as w130n30 or w140n30 or e130n20 etc

With the scenery the all start with w or e
and the second alpha number is either n or s for North or South, however as mentioned I do wish to sort other files as well so strictly speaking my main need is to sort by the first 5 characters and the extension's only :)

hope this helps ?

Michelle


Report •

#23
April 26, 2010 at 02:14:22

well, a good safety-test is to use echo instead of commands.
just have the batch output to a "fake batch" file:
>> fake echo move /y %%a test
(just a simple example) You would never run a "destructive" script or program without testing first, as i'm sure you know.
as for multiple extensions - best i've figured:
for /f "tokens=*" %%a in ('dir /b /a-d ^|findstr /E /g:exts') do (
echo qualifies: %%a
::: process the file
@echo off
)
::----
now, FINDSTR will use the file "exts" (where-ever it might happ to be). (look at FINDSTR /? if not familiar).
exts only has to have the extensions, one per line:
.doc
.pdf
.txt

Report •

#24
April 26, 2010 at 03:45:34

nbrane, again thank you, but I am not sure how to integrate that into a file move or copy?

if sorting files by moving from:
G:\Migrate
to
I:\Documents

how would your script be written...
is it like this?

for /f "tokens=*" %%a in ('G:\Migrate /b /a-d ^|findstr /I:\Documents /g:exts') do (
echo qualifies: %%a
::: process the file
@echo off
)

sorry if I messed this up but I'm lost here :/ Did say earlier strings are something I'm not good with.

Michelle


Report •

#25
April 26, 2010 at 04:50:09

I am just trying out the batch file's on PC#2 at the moment, can we hide these from being shown on the screen please ?

Either running hidden, or in system tray ?

Update! 26 April 18:26PM
I am having some problems with the script and the statflag ? where is this stored ? is it stored in PC memory or is it a file ? I must be doing something wrong lol things are looping ok and im seeing stars but nothing happening as regards files being moved.

Michelle


Report •

#26
April 26, 2010 at 15:51:40

statflags:
statflag is just a small file, stored wherever is convenient to the batchfile (i just used the CurrentWorkingDirectory). The contents of the file are also irrelevant - the script only tests for the existance of the file, so it can be null content, or it can be a piece of information if there's something that needs to be communicated, such as time/date, or number of files. It could also be an environment variable if you don't want to use files but that's a real major pain in the butt. the only requirement is that both scripts (pc1, pc2) are in exact agreement as to the location and name of the flagfile. Whenever i'm in doubt, i use the root (c:\) but i'm sure most other programmers would serisously frown on that. Just make sure that both sets of
scripts agree on and address the exact same paths and filenames for their respective statfiles.
running minized:
i would reserve this for the very last step, because you will probably need to consult the screen outputs, but:
start /min xxx.bat
should do it, mostly. If you need it to be even further invisible,
(not in taskbar) vbscript will probably be needed (xxx.vbs):
set wsh=createobject("wscript.shell")
wsh.run "xxx.bat",0
then kick it off:
cscript /b xxx.vbs
you can test this using the sleep thingey:
::xxx.bat:
echo start:%time% >> xxx.bat
sleep 30
echo stopping: %time%>>xxx.bat
goto :eof
then cscript /b xxx.vbs and you will (hopefully) see nothing, but 30 seconds later, the xxx.bat will have the added stop-time.
sorting:
referring way back to the top:
if exist w18*.tgz copy w18*.tgz "I:\scenery\w18\*.tgz"
and the latest information:
w130n30 = west130 Degrees & North 30
so like this?
I\scenery\w13\w130n30.tgz
I\scenery\w13\w130n50.tgz
I\scenery\w13\w130n30.doc (?)
I\scenery\w13\w130n30.pdf (?)
or:
I\scenery\w13\w130n30.tgz
I\scenery\w13\pdf\w130n30.pdf
I\scenery\w13\doc\w130n30.doc
i'm just not clear on how you are organizing the files, yet.
No need to cook something up and just have to re-cook it,
so i'll wait on your clarifications exactly how you want the dir structure to be.
ps, just noticed this too:
PLUS is it possible (in flag.bat) to have a check for disk LOCK Drives G: & I: or any for that matter ? such as when running a defrag on PC#2 ? or PC#1 ?
this should not be a problem, just have whatever script is running the defrag or the scandisk etc. to first remove the statflag from the sending computer:
del x:\downloads\statfile
defrag c:
::then whenever it is ready to receive, restore the statfile:
>> x:\downloads\statfile echo ok
::----
this way they communicate with each other, like a simple "handshake" protocol.

Report •

#27
April 26, 2010 at 19:31:47

Thats great nbrane, I been busy all day was late coming to check the latest post been awake 20 hours, so gonna grab some sleep and catch up tomorrow hopefully get these flags sorted out tomorrow I may have crossed my file paths somewhere see you's tomorrow thanks :)

Michelle


Report •

#28
April 27, 2010 at 10:29:01

OK had a nice sleep, and I thought based on my confusion I would write down some more information in a word document to help me sort out my logic so here is what I wrote a while ago!

I am getting confused so decided to write it down to try and get this straight in my mind!
As was said their is not much information about my system so here goes :)

1/ NETWORK!
First off I realised I have a network problem, PC2 is not able to send files to PC1 unless the second network adapter on pc1 is enabled. I disabled it because it was the cause of internet drop outs, as the primary adapter on pc1 is not allowing incoming from other pc's on the network this poses a problem. My original objective on pc1, was to optimise speed by having 1 network adapter for Internet traffic only and the 2nd adapter on pc1 for Local Area Traffic only!

Some times the above works! The 2 network adapter's are NOT bridged and I do not know how to do this or if I want too, my aim was to isolate Internet traffic on my Local Network for data security from being hacked.

Problem windows 2000 on pc1 often swaps network adapters and tries to use the wrong one for Internet traffic, the one which points to pc2's IP and not the router, = No Internet access)

PC2 however has only one network card at the moment, I have another I am thinking of fitting for redundancy and to perhaps sort the problem but need help with that.

2/ Batch files, I figured out why the STATFLAG is not working, pc2 is not able to write the statflag to pc1 so we need a slight rethink.

3/ Basically PC1 needs to manage it's own statflag which PC2 can never reliably touch until my network is sorted out! PC1 can however always access PC2 via this Network card used for the internet, so clearly I have not got the Internet and LAN separated yet, if I try to set PC2's Network to use PC1 for LAN traffic I get Internet drop outs not sure why this is? Anyway those are my problems explained with the network.

COMMENT TO SELF! TO GET THIS RIGHT IN MY HEAD:
LOGIC –

*** LOGIC ***

a) PC1: When a-attrib files ready, check PC2 ready (Base on 10 Minute Ready FLAG at PC2)
b) If PC2 Ready, PC1-copy files to PC2, Else PC1 loop's 30 Second wait cycles ; Until PC2 Ready
c) PC2 (10m Flag Exist) PC1 copy's Files PC2, (remove (a) attribute from files copied )
d) PC1 sets (File's Copied flag) ON PC2 so PC2-Knows files are waiting!
e) PC2 lookfor.bat sorts files in directories, when done removes: PC1-(File's Copied flag)
f) PC2 lookfor.bat goes into a 30 second loop looking for (File's Copied flag) made by PC1
f) PC1 starts again from a) above

Another thing I need to mention is PC1/2 = my actual real computer name as known over the Network.

I think we really need 2 flags a rdyflag for 10 minute ready status flag, this can be deleted at boot time by flag bat as the first job, before RECREATING a new one after 10 minutes.

One of the things that confuse me is that we seem to be using only one flag, and there are 2 situations 1 is that PC2 is up for 10 minutes, and 2 that files are ready to be sorted so if we had a flag for each purpose I will not be so confused :p

2nd a statflag made when files are ready to be sorted ! Called: srtflag

rdyflag flag being needed before PC1 sends files across ….
I think storing most flags in a special folder on \\PC2\stat\* locally> as G:\migrate\stat\rdyflag
and G:\migrate\stat\statflag
on pc2 would be best, as both PC1 & 2 can access these folders, PC1 only needs to create a local flag for itself if PC2 is off-line.

I hope I have managed to get this all right ?

Michelle


Report •

#29
April 27, 2010 at 11:14:49

Problem windows 2000 on pc1 often swaps network adapters and tries to use the wrong one for Internet traffic, the one which points to pc2's IP and not the router, = No Internet access)
Sounds like someone needs to review their routing tables / network addresses.

Report •

#30
April 27, 2010 at 13:11:07

Razor2.3 > LOL well that could be the answer yes, will have to deal with the routing tables later I just want to finish sorting these batch files out as copying does work OK from PC1 to PC2 and that's the main thing.

Michelle


Report •

#31
April 27, 2010 at 13:37:15

"Sounds like someone needs to review their routing tables / network addresses"

yes, there's definitely a monkey in the woodpile where the network is concerned. I'm very new to and very bad at network tshooting, so i can't help much there (you might post a different thread to the networking forum and get some competent help)

as for the statflag(s), i guess in all the confusion, you lost a flag, but i did have two flags, the "i'm ready to receive" flag posted by pc2, and and the "i'm done sending this batch" flag posted by pc1. But you have the right idea, and your analysis is very good (i do that too, with complicated projects).
The flags don't have to be on complementary computers, they could all be on pc2, that way pc1 can always post-up a flag, and pc2 can control (create/delete) its own flags. Also a thought i had, pc2 needs to "switch off" pc1 while it's moving/sorting so pc1 won't be trying to send new content which would bolix up the sort, i think. If #2 can't dependably access pc1, put all the flags on #2.
pc1 loops:
:top
If files-to-download,
start downloading
:done-downloading
move all files to .\complete
if exist \\pc2\migrate\stat\recvrdy then
cd complete
:: note that xcopy will simply do nothing if there's no "A"-files pending.
:: you could put a test here, but xcopy does that so it would be redundant/unnec.
xcopy /m *.* \\pc2\migrate
::now post the i'm-done-sending flag
echo ok > \\pc2\migrate\stat\senddone
goto top

pc2 boot:
sleep 600
echo ok > \migrate\stat\rcvrdy
start lookfor
:lookfor
if not exist \migrate\stat\senddone
sleep 30 (?)
goto :lookfor
end if
(else, senddone flag is up)
:: turn off the faucet
del \migrate\stat\rcvrdy
do move/sort
:: remove no-longer-relevant (expired) flag
del \migrate\stat\senddone
::reset rcv ready-flag
> \migrate\stat\rcvrdy echo ok
goto :lookfor
::-------------
there might be some other considerations, but this seems like the gist of it. Since pc1 and pc2 both have read/write access to pc2, us it for the flags.


Report •

#32
April 27, 2010 at 14:33:59

Ortorea, do you still need help with the "pseudo code" part ? It just means : any programming (in any language) begins with the idea of, first I do that step, which is this or that conditional statement, and then I do that, etc. etc. (from Response 7)

Report •

#33
April 27, 2010 at 15:20:45

PC2 **************************************************************
I kind of got something to work on PC2, the batch file is working but I had to make some changes as my paths are more than one and could not see how to make path changes to the first part of the line beginning with for /L>
for /L %%b in (18 -1 12) do move /y w%%b*.tgz "I:\scenery\w%%b\*.tgz"

So need to be able to see where it is moving files from!

What I really need is some simple way of being able to use path variables i.e. if my path is I:\my-files\docs
I need a way to convert that I:\my-files\docs
to a simple variable using = mfd20 or something, I know equation;s can convert a long string to something much shorter and if that is the case can we have something like that set-up at the very start of where the file moving begins so I know what it is ? I just need some flexibility with the batch..

PC1 **************************************

On PC1 I can not get this following section to work!, the script just seems to end after doing nothing but rolling some command options about ftp.

@echo off

:download
:: this is the routine that is downloading the files into the temporary-storage before moveing them to "complete"
ftp -s ftpscrpt
:: at this point, let's assume that the files are ready to move:
move *.* .\complete
: now check pc2 status
for /f %%a in ('ping venus6 ^|find "Reply"') do (
:: the pc2 is not there, so remove the status flag
if errorlevel 1 (
del statflag
goto :download
) else (

*************************************************************

It never goes past else or something is broken ?
Perhaps we need to avoid ftp and just do a simple ping check, or better still just a check to see if a known existing folder exists on PC2 is present with files in it ?
that worked for me before.

Michelle

PS UPDATE > IN REAL DIRECTORIES PC2
I have one folder specially for the flags all flags go their I call sortflag = srtflag and readyflag = rdyflag
Both flags share same network path this is the real path \\PC2\tor-mig\stat\ %flags%
also known AS G:\PC2\tor-mig\flag\ %flags%

for security reasons as this is a public forum PC2 and PC1 actually have different real names, I just use PC? based on simplification of the batch.


Report •

#34
April 27, 2010 at 16:03:25

TVC WROTE "Ortorea, do you still need help with the "pseudo code" part ? It just means : any programming (in any language) begins with the idea of, first I do that step, which is this or that conditional statement, and then I do that, etc. etc. (from Response 7)"

I'm not sure just yet, I just don't want to lose my current train of thought, at my age I have a hard time with learning new things :p lets see if we can get this existing script worked out, their are some things like hiding the batch files in the system tray or other things that might lead to looking at alternatives but at the moment I just want something stable and simple that works for multiple files sorting. The thing that drives me CRAZY is this for /L %%b in (18 -1 12) I don't know what this is ? I like to see some sort of path structure or perhaps an explanation of what this is ? (If we can get it working then later it could be expanded to the 3rd PC, but that's not important right now)

Michelle


Report •

#35
April 27, 2010 at 17:39:23

Dear nbrane, you said yes, there's definitely a monkey in the woodpile where the network is concerned. I'm very new to and very bad at network tshooting, so i can't help much there (you might post a different thread to the networking forum and get some competent help)

NETWORK!
Well actually I am usually quite good with networks, the problem is windows 2000 and windows XP always seem to have issues between each other on networks, the one problem is I keep my internet adapter stealthy and want my LAN friendly to my local computers! (plus older windows 2000 uses an older tcp/ip stack than windows XP I believe) I also have software firewalls and don't like dropping my security levels especially with recent virus's floating around, I think the second network card on PC2 will help as it will enable separate routing via another switcher box.

BATCH FILE CONTINUED!
nbrane said Also a thought i had, pc2 needs to "switch off" pc1 while it's moving/sorting so pc1 won't be trying to send new content which would bolix up the sort, i think. If #2 can't dependably access pc1, put all the flags on #2.

YES Good POINT I am thinking, perhaps the simplest would be to set 1 busy flag. IF PC1 is about to copy files over as a final check it looks for busy flag on PC2, this is created by which ever script is running first / or on a delayed start after initiating a busy flag, and if the other script sees it then it aborts and waits until it is removed. But I think you have already done something similar in post 31 with your re-write have to analyse it and see :)


Report •

#36
April 27, 2010 at 18:22:53

i spent about half an hour addressing all your issues, and I usually cut/paste to notepad but of course i didn't this time and it got the @#!^$ "unable to display this page" crappola, so the whole thing evaporated. sigh.
let me see if i can get most of it put back.

the ftp thing was just to act as a placeholder representing your current method of downloading. You must have some arrangement, either ftp, or a batchscript, or wget, so just swap out the ftp thing, that's "pseudocode"!

the for /L just counts backwards from 18 to 12 in order to generate the filenames.
I only went backwards because thats the way you had it in your original.
it does the equivalent of:
for /L %%b in (18 -1 12) do (
generates the series 18 17 16 15 14 13 12 into variable %%b
which is used to generate the equivalent of:
move /y w18*.tgz I:\scenery\w18\
move /y w17*.tgz I:\scenery\w17\
move /y w16*.tgz I:\scenery\w16\
it's just a lot shorter than explicitly naming each item. lets put an echo in here to help clarify:
(and, while at it, use variable-pathname)
::: PC2 LOOP-SCRIPT
set pc2path=G:\tor-mig\
:movesort
:: first, turn off the faucet
del %pc2path%\flag\rdyflag
for /L %%b in (18 -1 12) do (
echo moving w%%b*.tgz "%pc2path%\w%%b"
pause
move /y w%%b*.tgz "%pc2path%\w%%b"
)
:: now turn the faucet back on
> %pc2path%\flag\rdyflag echo ok
:lookfor
sleep 30
if exist %pc2path%\flag\srtflag goto :movesort
goto :lookfor
and yeah, now that the statusflags are in use, the ping-test is not necessary. just test the existance
of the flagfile:
:: PC1 LOOP SCRIPT
:top
:: downloading stuff here...
:: when done downloading current batch, begin next section
if exist %pc2path%\flag\rdyflag (
pushd complete
xcopy /m *.* %pc2path%
> %pc2path%\flag\srtflag echo ok
popd
::then resume downloading, whatever you're using to do that
goto :top

I've tried to use your "real" variables and paths, but i'm still somewhat in the dark about
a lot of these. I have a bad habit of using sloppy and/or inconsistant naming and assuming
others know what/where to substitute their "real" locally-specific values.
(like the ftp thing, a perfect example, sorry about that).

is this a mistake, or am i missing something?
"Both flags share same network path this is the real path \\PC2\tor-mig\stat\ %flags%
also known AS G:\PC2\tor-mig\flag\ %flags%"
is it \stat or \flag, and do you mean
G:\tor-mig\flag (equals \\PC2\tor-mig\flag, ie: G: mapped to \\pc2\)

my last suggestion, before the crapping system smoked my post, was you might want to
start a new thread, as this one has gotten very long, beginning with a dump of your current
scripts with as much accuracy as is consistant with security concerns. (path & variables etc,
no ip other sensitive matl.) A lot of what's in this thread is either irrelevant, finished/done,
obsolete, or (in my posts) simply wrong!

note to myself:
I will never, NEVER compose a lengthy response in these crapping forum-forms AGAIN!
so if the formatting sucks, that's my fault because i'm using notepad and i never know when
or where to put line breaks.


Report •

#37
April 27, 2010 at 21:43:39

Dear nbrane, don't worry same thing happened to me tonight only I built a batch and spent over 1hour and 20 minutes editing it then I suspect the flag.bat as it was called, with the command:
echo ok > g:\tor-mig\stat\rcvrdy
I got something wrong and the cmd window kept giving me bad command errors, as a result my VERY laborious effort with the new batch was ZEROED out NULL'ED omg I was so sick :(

YES ALWAYS, ALWAYS, write your work first in word-pad or Notebook I learned that lesson too my friend. The Internet is very bad at times.

REGARDING:
"Both flags share same network path this is the real path \\PC2\tor-mig\stat\ %flags%
also known AS G:\PC2\tor-mig\flag\ %flags%"
is it \stat or \flag, and do you mean
G:\tor-mig\flag (equals \\PC2\tor-mig\flag, ie: G: mapped to \\pc2\)

Sorry I was having an off moment, concentration issues,
Truth is PC1 has not been formatted since 2005 the whole operating system is the same, it never crashes, as a result their are thousands of files and many directories that need sorting out. I hope that I can use the batch files to also do some tidying up as I do not want to spend DAYS or WEEKS even sorting out all the files.

PC2 is pretty much the same, as I rarely have downtime as my entire operating system C: drive is stored on a Boot-able restore DVD's, compressed of coarse. PC1 has MAIN drive letters from C: all the way to J: and network drive mappings all the way to Y, PC2 also has similar Drive letters so perhaps you have some idea how much sorting their is to do!

Yes we can start a new thread, I will need to recover from losing my batch file for PC2 however which was a mixture of mostly your work and some simplification of some area's I could better understand.

I will be getting some sleep soon as I'm tired, flagging a bit. I really appreciate you helping me and I hope we both learned something so far :)

Michelle


Report •

#38
April 27, 2010 at 21:57:25

OK new thread here for later!
http://www.computing.net/answers/pr...

Report •

#39
October 9, 2010 at 01:09:24

Dear tvc, back in April you suggested using this

************************************************************************************
Question regarding server (computer 1) which checks client (computer 2):

If only actions can be done, after the client is up for consecutive minutes, this is what you can do (in pseudo code):

-set sounter to 0
-start loop
-check if client is available
-if available, add 1 to counter
-if not available, set counter to 0
-if counter is 10 or higher, exit this loop
-sleep 1 minute
-otherwise (counter less than 10) go to begin loop
-perform action which can only be done with client up and running
************************************************************************************

NOW - I am currently experiencing a problem with a new server computer I have put together, the network keeps going down after a period of about 1 day, I need a backup script to reboot the computer Automatically if and when the network goes off-line, I do not know what is causing my network to display this message with a yellow explanation mark which says "This connection has only partial connectivity available" but it is causing my voice server and irc client to stop working, UNTIL A REBOOT IS MADE.

What command would I use in an IF EXIST statement to check if their is a route to the ROUTER ? and if not use the SHUTDOWN -r -f
commands ?

Michelle


Report •


Ask Question