Batch Scripting

Started by benthehutt, March 16, 2005, 06:16:01 PM

Previous topic - Next topic
In windows shell programming (cmd), is it possible to compare two different lists of files and copy ones that aren't on both?  I can write a script that compares and writes another file with the uncommon files on it, but I can't get past there.  Should I just scrap it and write it in something else?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

Hey,

I honestly don't ever remember the dos command copy or xcopy having the ability to only copy files that don't exist. I could be wrong, but I don't remember it -- it's been a long time though.

I looked at the help for the copy command and didn't see anything.  Looking at the 'help' screen, I can only think of generating a third list and then that would be the files to copy, but I don't know the situation and my batch scripting abilitiy is very limited.

I personally use whatever works (and that I know).
"My Terminal is my Soul"

I don't think you can do it with BATCH .. but it is so long since i have had the need to use it, i couldnt really tell you what it does and doesn't support.

A simple VBScript would do it.

using the the DIR command and strip and output each list of files to their own arrays .. then do a compare on the arrays .. and everything that is in list X and not in list Y get's copied.

Easiest way i can think of off the top of my head.

I am not suffering with insanity... I am loving every minute of it.

Theres always a way to do it with a batch file. My suggestion would be to get a hold of the Windows 2003, Windows 2000 Server, Windows 2000  Professional and NT4 Server resource kits. Theres a slew of "unsupported" tools the MS guys toss out there to make admin life a little easier and I think theres one in there somewhere. Once you find one you can write some scripts to use those apps as they are all usually standalone EXE's or VBS's.

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

http://www.microsoft.com/windows2000/techinfo/reskit/tools/default.asp
"A well known hacker is a good hacker, an unknown hacker is a great hacker..."

I don't care what your parents told you, you aren't special.
  • https://github.com/tazinator

I'm not sure if you can do it with xcopy, but this is what I have in my batch file so far (I don't have the code with me):

First, I use dir /b on %SystemRoot%/Fonts to make a list without a heading or summary and redirect it to a text file.  Then I do the same for the other boxes so I have a set of "databases."

Next, I use fc to compare the files and redirect its output to a text file.

So it does compare them and I can tell what fonts are not on each machine, but I can't just use the text file as input to copy because there is a header and footer that fc makes.  There is no switch that turns it off either.

I haven't yet looked at the links Taz sent me, but before I do, I just wanted to know if batch could cut out certain lines of a text file.  Then it would be easy to use the text file fc made to copy the fonts to each machine.

Thanks for all the help-- :)
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

are you asking if a batch file can modify a test files specific lines or ignore some lines and read others?

Editing only some lines may not be possible (never tried it so cant be sure).

Ignoring some lines and reading others yes, but its tricky. The command within the batch file would be the following:
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]

I think you need something like
for /F "skip=# tokens=#" %%a in (sometextfile.txt) do call taskbatchfile.bat %%a


Breaking it down some....

skip=# - specifies the number of lines to skip at the beginning of the file.

tokens=# - specifies which tokens from each line are to be passed to the for body for each iteration. This will cause additional variable names to be allocated.  The m-n form is a range, specifying the mth through the nth tokens.  If the last character in the tokens= string is an asterisk, then an additional variable is allocated and receives the remaining text on the line after the last token parsed.

You could also use in the options area:

delims=### - which specifies a delimiter set. This replaces the default delimiter set of space and tab.

Its going to take some time to get it the way you want but I think the "FOR" command is key for what your looking to do w/ a text file. Its a bit of a trick tho so its going to take playing with before you get it right.

When in doubt...
C:\for /?[/b]
Be ready for 4 pages of help tho ;D
"A well known hacker is a good hacker, an unknown hacker is a great hacker..."

I don't care what your parents told you, you aren't special.
  • https://github.com/tazinator

Hey, you replied!  Sorry about my late reply...

Anyway, your post is really confusing and I'm not sure how to use it.  Are you saying that with this FOR command, cmd just picks out lines of code from the file and executes them?  As in, it cuts them out of the file and reads them into cmd like a command?

Also, I'm not sure I understand the TOKENS switch.  What do you mean by tokens, what are they?  I get lost around the m-n shannanigans.

Sorry, I'm not very well versed in batch. :(
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

Not sure this is totally relevant or useful, but I've been struggling to find a way to make a timer in batch, here's a jerry-rigged way:

ping 1.1.1.1 -n 1 -w <insert time in milliseconds here>

it's not exact, but it actually works pretty well.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

I am not sure what you are trying to accomplish with the ping command but maybe the sleep command could work for you?

sleep /?

for more info on it.

Thanks,

Wilnix
alt email address: wilnix@hackphreak.org

SMF spam blocked by CleanTalk