From: Jim Hunter Newsgroups: comp.os.msdos.djgpp Subject: Re: A Globbing Problem Date: Mon, 21 Apr 1997 19:19:47 -0400 Organization: Johns Hopkins University Applied Physics Laboratory Lines: 110 Message-ID: <335BF613.5BAB@jhuapl.edu> References: <3357B4DA DOT 36D8 AT jhuapl DOT edu> NNTP-Posting-Host: sts-jdh-pc.jhuapl.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Jim Hunter wrote: > > Can someone tell me why my code snippets here > aren't working. > > I'm having a problem with command line > globbing of long file names. My > program is given a list of file names > as inputs on the command line. After > some processing, I want to conditionally delete > the files after checking the file attributes. > The program works fine except in the case > that there are files with long names getting > globbed. > > -------------------------------- > ex: dir contents > > A.X > B.X > C~1.Y => long name = C.X.Y > > --------------------------------- > command lines: > > prog *.X -> works fine > > prog C~1.Y -> works fine > > prog *.* -> chokes when it gets to the argument C~1.Y > > I am using the call: > err = _dos_getfileattr( filename,&attr); > > What's happening is that C~1.Y is getting passed to > the program as C.X.Y after the *.* expansion and > _dos_getfileattr returns telling me the file > doesn't exist (returns 0xFF for attributes). > > Another thing that puzzles me is that stepping > through the code in gdb with the same command line > i.e. | gdb: r *.* | works o.k. > > Thanks for any clues or work-arounds you can > give me. > I think I've found a bug here with either the DJGGP compiler or Win95 in the behaviour of _dos_fileattr on globbed long names. I've included a short test program and would be grateful if someone with a similiar system could run this and tell me your results. I'm running Win95 with DJGPP v2.7.2. A workaround I've found is to use _chmod with 0 agruments. ----------------------------------------------------------- #include #include #include main(int argc, char **argv) { unsigned int attr; char *file; if (argc!=2){ printf("usage: attr file\n"); exit(1); } file = argv[1]; printf("file: %s\n",file); if(_dos_getfileattr(file,&attr)) printf("dos_getfileattr: error for %s\n",file); else printf("dos_getfileattr: %03o\n",attr); if((attr = _chmod(file,0,0))==-1) printf("_chmod: error for %s\n",file); else printf("_chmod: %03o\n",attr); exit(0); } ------------------------------------------------------------- The problem only occurs when you glob long names on the command line. Run this on, say, the "Program Files" directory from the command line. Running c:> attr c:\progra~1 should print file: c:\progra~1 dos_getfileattr: 021 _chmod: 021 Running c:> attr c:\progra* should print file: c:\program files dos_getfileattr: error for c:\program files _chmod: 021 thanks, ---- Jim