I’m trying to gzip a whole bunch of files on Windows, but the Windows version of gzip doesn’t seem to support wildcards. So I can’t just do “gzip *.txt” like on unix. Is there a way to use a batch file or something to expand the wildcard and loop through the matches, feeding each one as an argument to a program?
No, I don’t want to use another compression program. I need the files compressed into separate files, not one big zip file containing all the files. Besides I’ve already written the program that uses the resulting gzip files and I don’t want to rewrite it.
Just a point of information - it isn’t the command that does the wildcard substitution on UNIX - it’s the shell. That’s why it works with everything. You type “argle *.txt” and “argle” is invoked as if you had typed “argle foo.txt bar.txt blech.txt”
Rather than address your specific problem, I’m going to make a reccomendation.
If you are used to UNIX utilities, you are ahead of the game getting ahold of a set of them for the PC, including a shell. For years every PC I’ve had any control over has had the MKS toolkit installed on it.
Trouble with MKS is that you have to pay for it. The cygnus utilities are free:
Personally, I think MKS is a lot better[sup]1[/sup], but, again, Cygnus is free. Either of the solutions should provide you with a UNIX look-alike shell, and common utilities like “sed”, “grep”, et al. The MKS toolkit provides a good version of vi for a Windows environment.
[sup]1[/sup] - MKS adapted UNIX commands to work with Windows metaphors, such as paths including drive letters, preserving the idea of a current directory on each drive, and so on (their ksh version knows the distinction between “cd d:” and “cd d:/”). MKS also comes with ksh, my shell of choice, rather than one of these various things that sprouted from csh. Cygnus has a concept of having to “mount” Windows paths as something which Cygnus utilities can then see as a UNIX directory structure. This sounds elegant. In practice, it’s annoying, particularly if you wish to do shell scripts which invoke normal Windows executables - you have to get back to the Windows file syntax to invoke them.
Actually, I just downloaded from that link I gave you - a quick check suggests that the newer versions of Cygnus may have remedied some of the problems I alluded to. I wonder if they’ve remedied the non-POSIX compliant command syntax they used to have as well.
I thought somebody would give the OP the DOS syntax for their specific problem in the meantime. Thanks.
Thanks. That almost worked, but it doesn’t seem to work on long filenames. The resulting gzip files have the shortened 8.3 character filenames. In my case that’s a big problem, since the long filenames contain vital information. Any way to get it to work with just Windows? Gzip itself seems to work fine with long filenames, but only if you give it the long filename as a command-line argument.
What version of Winodws is it? In NT, 2000, and XP, the ‘for’ command above should properly pass long file names to the gzip command. I think that 95, 98, and (shudder) ME would use the 8.3 version of the ‘for’ DOS command, so I wouldn’t expect them to work.
Also, you may need to put the file name parameter in quotes in case a file name contains a space, assuming that gzip would see an un-quoted space as a separate command.