Fog Creek Software
Discussion Board

creating a bunch of word files

i am an old unix hand trying to learn how to program windows.  I don't really know how to do quickie "shell script" type things on windows. for example, i need to create 10,000 word documents, to test a drag and drop bulk check in program I am writing.

what is the windows way to do this? i.e create a bunch of dummy word documents named like demo1.doc, demo2.doc  ... etc.

also is there a good book that would describe "tricks" like this? kinda like the perl and/or unix cookbook books from oreilly.


windows n00b
Tuesday, June 24, 2003

The answer is for the most part Windows developpers/admins do not script.

The Microsoft answer is "Window Scripting Host"  plus JScript or VBScript, search MSDN.

The best answer is Perl, in particular ActivePerl from ActiveState.

Anonymous Coward
Tuesday, June 24, 2003

nOOb -

Yep, anyone familiar with *nix command line will not have a fun time with Windows' command shell or their "shell scripts".

But, it's gotten better with NT and versions since.  To get you going on writing shell scripts on DOS, here are a couple of places to start:

From your 'winders' box, click Start->run, then type in 'cmd'. You'll get a dos window with a command line, at the prompt, type 'help' and you'll get a listing of the commands available to you from the default command interpreter, 'cmd.exe'.

You can also click Start->help, and search for the commands from the command line list you just got and you'll get a bit more info and discussion, along with some examples.

That should get you going on dos' equivalent of 'shell scripts' and will certainly provide you enough power to basically copy a file over a bunch of times, slightly changing the file name.

If you want more advance scripting capabilities, from that same help window, check the index tab for 'scripting host', which will give you the top-level entry into info about a gui-based and a command-line-based scripting host (wscript.exe, and cscript.exe, respectively). You can follow your nose from there through the info. There's more power with those environments than plain 'dos', but it's more than you need for the problem you're facing.

good luck,

Tuesday, June 24, 2003

nOOb, you may want to think about these alternatives too:

Heavy: Get yourself a *nix box and mount your W2K drive from the *nix box. Keep all your project work on the W2K box (it's my CM checkout target), but use whichever environment suits what you're trying to do at the moment.

Lighter: Install cygwin's environment on your W2K box. That'll give you a bash environment on your W2K box so you don't even need to bother with Window's scripting/shell command capabilities -- you can stick with what you know and are probably more efficient in anyway.

I have both. When I'm at work, I normally use my linux box to which I have mounted my W2K laptop's drive. When working from home, though I've got a linux box at home, it's less trouble for me to just use cygwin's environment directly on my laptop whenever I need a bash/*nix-like environment.

Tuesday, June 24, 2003

i grabbed active perl and already finished the task! thanks for the advice!

windows n00b
Tuesday, June 24, 2003

Doesn't MS ship Perl in the OS resource kits? I seem to remember it being included in the NT 4.0 resource kit.

Just me (Sir to you)
Wednesday, June 25, 2003

I realize you're done already, but another option is to use Python to talk to M$'s  COM objects.  Look at chapter 10 of Learning Python.  Just think, you can subvert the tools used by virus writers worldwide for good :)

Wednesday, June 25, 2003

If its okay that they all have the same contents...

for /f %i in (1,1,10000) do copy source.doc dest%i.doc

Wednesday, June 25, 2003

One other utility that you may find useful is:

It provides a nearly complete emulation of the *nix style scripting environment... complete with lots of GNU utilities etc.  Then you can still enjoy all of your old *nix style commands :)

Tom Davies
Wednesday, June 25, 2003

Some people don't like the way Cygwin works (others like it a lot).

If you want a Unix-like shell without Cygwin, try the utilities from It includes sh and zsh.

There is also a nice Windows version of tcsh:

Any of these will give you Unix-like shell commands and of course it's even better when combined with Perl or Python.

Nate Silva
Wednesday, June 25, 2003

While there's lots of interesting advice here for general scripting problems, for that PARTICULAR problem (creating the .doc files), I would just use VBA, assuming you have a copy of MS Word.

It would only take a few lines of VB to do it.  If you like, email me and I'll send you an example...

Tim Lara
Wednesday, June 25, 2003

*  Recent Topics

*  Fog Creek Home