globbing source for C

O

Owner

I'm looking for source of globbing. because win 7 does not
change * to file names in commmandline.

So, looks like I have build one.

can anyone give me help by pointing at somewhere start with?
 
H

Heinrich Wolf

Owner said:
I'm looking for source of globbing. because win 7 does not
change * to file names in commmandline.

So, looks like I have build one.

can anyone give me help by pointing at somewhere start with?

On Windows you might look for findfirst(), findnext(), findclose().
On Linux you might look for opendir()
 
S

Shao Miller

I'm looking for source of globbing. because win 7 does not
change * to file names in commmandline.

So, looks like I have build one.

can anyone give me help by pointing at somewhere start with?

With apologies for being off-topic for C, here's some batch that might
help, too:

@echo off
goto :_main

:: Create an environment variable with a list of files
:: that match a globbing pattern.
::
:: Parameters:
:: 1 : The globbing pattern to be expanded
:: Returns:
:: _glob : This variable is set with the list of files

:_glob
set _glob=
for /f %%a in ('dir /a /b "%~1"') do (
call :_build_glob "%%a"
)
goto :eof

:_build_glob
if "%_glob%"=="" (
set _glob=%1
) else (
set _glob=%_glob% %1
)
goto :eof


:_main
echo.
echo Testing pattern *.bat...
echo.
call :_glob *.bat
echo _glob=%_glob%
echo.
echo Testing pattern *.t?t...
echo.
call :_glob *.t?t
echo _glob=%_glob%
 
K

Keith Thompson

Heinrich Wolf said:
On Windows you might look for findfirst(), findnext(), findclose().
On Linux you might look for opendir()

<OT>

On Linux, you probably don't need to do you own globbing, and you
shouldn't try. If I invoke a program with the command line

./program *.txt

the program will see a list of all the matching files; it will have no
way of knowing they were expanded from a wildcard. And if one of those
file names happens to have a '*' in it (which is perfectly legal), you
don't want to try to re-expand it.

</OT>
 
J

James Kuyper

On 05/12/2011 09:07 AM, Datesfat Chicks wrote:
....
c)It is my understanding that the treatment of command-line arguments
has always been different in Windows (i.e. it predates Windows 7 by
far). *nix globs for you, Windows does not.

It's not the operating system that does those things, it's the shell
(tcsh, on my machine), or the command line interpreter (CLI)
(command.com, on my wife's machine). Use an unconventional shell or CLI
and the behavior could be quite different, on both operating systems.
 
R

Roberto Waltman

Owner said:
I'm looking for source of globbing. because win 7 does not
change * to file names in commmandline.

You can find working examples in the source code of the various shells
provided by the Cygwin project.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top