Mail Archives: djgpp/1997/12/20/04:45:32
From: | kjcole AT well DOT com (Kevin Cole)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Q: How do I pass long pathnames from the command line?
|
Date: | 19 Dec 1997 18:06:06 GMT
|
Organization: | The Whole Earth 'Lectronic Link, Sausalito, CA
|
Lines: | 97
|
Message-ID: | <67ed2e$6vl$1@was.hooked.net>
|
NNTP-Posting-Host: | well.com
|
Summary: | C:\>forget "D:\Program Files\" *.ABC fails
|
Keywords: | Win 95, long directory name from command line
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
[Source program at end of message -- KJC]
Hi. I'm a FORTRAN programmer with a lot of experience with assember
languages on old mainframes, but very little C experience, though I've
been a Linux user for 3 years now. I recently downloaded my very first
copy of DJGPP from www.delorie.com (so I am assuming it's fairly current)
to a Windows 95 machine, and today I added this newsgroup to my list.
Below is a program I hammered together quickly, using the libc reference
examples. I'm still working on it, so the comments reflect what it WILL
do when finished. It mostly works, as far as I have taken it, but I cannot
figure out how to pass directory strings like "C:\Program Files\" to it in
a way that it will understand. I've tried various combinations of forward
slashes, backslashes, case changes, quotes, etc. (I'd like to avoid using
C:\PROGRA~1\, since this is supposed to be general enough to run on
several different machines, and not all will be searching through the
exact same tree.)
Is there a simple answer or can someone point me to the right docs?
------------------<80-column, fixed-width-font text below>--------------------
/************************************************************************
* *
* *** FORGET *** Written by Kevin Cole 97.12.18 *
* *
* This was written in response to a need to empty cache files in *
* several subdirectories of unknown name and/or depth. The files to *
* be deleted all end with the same extention but the root (base) name *
* may vary. The idea was to construct something similar to the NT *
* FOR command, or the VAX/VMS DCL commands, or Unix's find or recurse *
* stuff. *
* *
* Usage: FORGET start_path "filespec" *
* *
* No parameter is optional. Wildcards may be used for the filespec *
* but all constants must be UPPER CASE and quotes MUST be used around *
* the filespec! *
* *
* Example: FORGET C:\ "*.ABC" *
* *
************************************************************************/
#include <stdlib.h>
#include <dir.h>
#include <errno.h>
#include <fnmatch.h>
char *spec;
int ff_walker(const char *path, const struct ffblk *ff)
{
if (fnmatch(spec, ff->ff_name, FNM_PATHNAME) == 0)
printf("%s\n", path); /* change to a delete function */
/* The above printf is for debugging only and will become a delete/erase *
* function when I get around to it. The if below is a temporary thing *
* to stop the program from walking the tree at a specific location. */
if (strcmp(ff->ff_name, "XXXXX") == 0) /* DEBUG */
return 42; /* DEBUG */
return 0;
}
int main(int argc, char *argv[])
{
printf("FORGET version 1.0 (c) Kevin Cole 1997\n\n");
if (argc > 1)
{
char msg[80];
spec = argv[2];
sprintf(msg, "__file_tree_walk: %d",
__file_tree_walk(argv[1], ff_walker));
if (errno)
perror(msg);
else
puts(msg);
}
else
{
printf("Usage: forget start_path \"filespec\"\n\n");
printf(" Quotes required, wildcard allowed, no lowercase\n");
}
return 0;
}
--
=========== Physical ============================= Virtual =================
Kevin Cole <Flatline> | E-mail: kjcole AT gallux DOT gallaudet DOT edu
Gallaudet Research Institute | WWW: http://www.gallaudet.edu/~kjcole/
Hall Memorial Bldg S-419 |
800 Florida Avenue, N.E. | Voice: (202) 651-5575
Washington, D.C. 20002-3695 | FAX: (202) 651-5746
============================================================================
"If they give you ruled paper, write the other way."
- Raw text -