Results 1 to 10 of 10
  1. #1
    EmuTalk Member Poobah's Avatar
    Join Date
    Feb 2004
    Posts
    475

    How can I manually expand wildcards into filenames in C?

    I've realised the flaws of Windows' wildcard expansion, and am now wondering if there is an easy and convenient way of expanding wildcards into filenames in C, using a GCC-based compiler such as MinGW. Also, is there a switch or something that can be used when compiling a program that prevents the OS from doing its own wildcard expansion on that particular program?

    My Site
    Batch-extract and re-archive individual ROMs from GoodMerged 7z archives into individual ZIP or JMA files. (Now a Windows GUI program!)

    Drug Free For Life: 98% of the teenage population has
    tried drugs at least once. If you are one of the 2%
    who hasn't, copy and paste this into your signature.


    • Advertising

      advertising
      EmuTalk.net
      has no influence
      on the ads that
      are displayed
        
       

  2. #2
    Mankind Member NoeOM's Avatar
    Join Date
    Jun 2006
    Location
    Cáceres, Spain
    Posts
    77

    Exclamation Please, be more specific

    Hi,

    Please, be more specific when asking. For the wildcards in C, i suggest the use of the strcmp function, for instance. If you are looking for files with the prototype fil*, then you can check the return value of a call to

    strcmp("fil",fileName)

    where fileName is the name of the file you are checking.
    It's only a suggestion since I don't know what data types are you using, what kind of functionality do you want, etc...

    And what do you mean by disable wildcard expansion for a program?
    by Noé
    More about me at my website

  3. #3
    EmuTalk Member Poobah's Avatar
    Join Date
    Feb 2004
    Posts
    475
    Quote Originally Posted by NoeOM
    Hi,

    Please, be more specific when asking. For the wildcards in C, i suggest the use of the strcmp function, for instance. If you are looking for files with the prototype fil*, then you can check the return value of a call to

    strcmp("fil",fileName)

    where fileName is the name of the file you are checking.
    It's only a suggestion since I don't know what data types are you using, what kind of functionality do you want, etc...

    And what do you mean by disable wildcard expansion for a program?
    In Windows, if I called:
    Code:
    program *.exe
    then Windows would automatically expand the "*.exe" into matching file names in the current directory. If I called any of the following examples:
    Code:
    program "*.exe"
    Code:
    program ..\*.exe
    Code:
    program *\program.exe
    then Windows would completely ignore the wildcard. I think, however, that it is possible to disable Windows' expanding of wildcards passed in command-line arguments.

    strcmp() doesn't consider two strings beginning with the same text equal, by the way.

    What I'm mainly looking for is an easy and convenient way to manually expand wildcards to matching file names, since Windows' wildcard expanding is extremely limited. Glibc appears to have something like this, which it calls "globbing", but the library is quite bloated.
    Last edited by Poobah; June 26th, 2006 at 09:35.
    My Site
    Batch-extract and re-archive individual ROMs from GoodMerged 7z archives into individual ZIP or JMA files. (Now a Windows GUI program!)

    Drug Free For Life: 98% of the teenage population has
    tried drugs at least once. If you are one of the 2%
    who hasn't, copy and paste this into your signature.

  4. #4
    ????????????????????????? Doomulation's Avatar
    Join Date
    Nov 2001
    Location
    ????????????????
    Posts
    8,780
    If all else fails, you could use FindFirstFile/FindNextFile since they expand wildcards and returns the matched files.
    Atashi wa juu-yon-sai no onna no ko! Atashi no namae wa Miizuki. Yurushiku ne!
    Nani? Atashi o shinjirimasen desu ka? Baka!
    "You're all doomed! Doomed, I say! Hehe... are we approaching the end of the world?"

    shikata ga kaite aru - "the instructions are written above"
    Need to download GoodN64 or instructions to use it? Need to check if it's a good or bad rom?
    Download: Glide64 | Hacktarux's wrapper

  5. #5
    Mankind Member NoeOM's Avatar
    Join Date
    Jun 2006
    Location
    Cáceres, Spain
    Posts
    77

    Revision

    Sorry, I was talking about strstr, not strcmp (my mistake).

    And for the command line arguments expansion... I think that this is a task performed by the OS and not dependant on your code so, I don't think there is any option to disable it (in the code of your program, maybe the OS can be configured)
    by Noé
    More about me at my website

  6. #6
    EmuTalk Member Poobah's Avatar
    Join Date
    Feb 2004
    Posts
    475
    I just spent ages working out how to use glob() and finding the appropriate libraries, and now it's turned out that GnuWin32 hasn't even ported that particular function yet, despite the fact that the Glob.h file is still included with their libgw32c package.

    Quote Originally Posted by Doomulation
    If all else fails, you could use FindFirstFile/FindNextFile since they expand wildcards and returns the matched files.
    Could you explain how to use those in C? I don't know a thing about Windows programming.
    EDIT: Never mind that last question; I've worked it out.

    EDIT 2: Is it just me, or does the WIN32_FIND_DATA structure only contain the file's name, and not its path? I understand that I can work around this by adding a path extracted from the original prototype to the file name, but all sorts of horrible things will happen if wildcards are in places other than the file name.
    Last edited by Poobah; June 26th, 2006 at 16:02.
    My Site
    Batch-extract and re-archive individual ROMs from GoodMerged 7z archives into individual ZIP or JMA files. (Now a Windows GUI program!)

    Drug Free For Life: 98% of the teenage population has
    tried drugs at least once. If you are one of the 2%
    who hasn't, copy and paste this into your signature.

  7. #7

  8. #8
    ????????????????????????? Doomulation's Avatar
    Join Date
    Nov 2001
    Location
    ????????????????
    Posts
    8,780
    Quote Originally Posted by Poobah
    EDIT 2: Is it just me, or does the WIN32_FIND_DATA structure only contain the file's name, and not its path? I understand that I can work around this by adding a path extracted from the original prototype to the file name, but all sorts of horrible things will happen if wildcards are in places other than the file name.
    It works on a directory level. So searching for "C:\*" returns all files (and folders) in C. To make it recursive, just check for directories and search them as well.
    Atashi wa juu-yon-sai no onna no ko! Atashi no namae wa Miizuki. Yurushiku ne!
    Nani? Atashi o shinjirimasen desu ka? Baka!
    "You're all doomed! Doomed, I say! Hehe... are we approaching the end of the world?"

    shikata ga kaite aru - "the instructions are written above"
    Need to download GoodN64 or instructions to use it? Need to check if it's a good or bad rom?
    Download: Glide64 | Hacktarux's wrapper

  9. #9
    EmuTalk Member Poobah's Avatar
    Join Date
    Feb 2004
    Posts
    475
    Quote Originally Posted by Doomulation
    It works on a directory level. So searching for "C:\*" returns all files (and folders) in C. To make it recursive, just check for directories and search them as well.
    Yeah, I understand that, but that's not really what I meant. I asked the above question, because I noticed that the cFileName string in the WIN32_FIND_DATA structure always contained only a filename, even if the pattern contained a path, such as "C:\*". If I sent the file to fopen(), it wouldn't work unless the current directory was C:\.

    It doesn't matter now, though, because I've written my own glob() function using FindFirstFile/FindNextFile, adding a directory extracted from the pattern to each returned file name. Thanks for the help, everyone.
    Last edited by Poobah; June 27th, 2006 at 07:13.
    My Site
    Batch-extract and re-archive individual ROMs from GoodMerged 7z archives into individual ZIP or JMA files. (Now a Windows GUI program!)

    Drug Free For Life: 98% of the teenage population has
    tried drugs at least once. If you are one of the 2%
    who hasn't, copy and paste this into your signature.

  10. #10
    ????????????????????????? Doomulation's Avatar
    Join Date
    Nov 2001
    Location
    ????????????????
    Posts
    8,780
    Quote Originally Posted by Poobah
    Yeah, I understand that, but that's not really what I meant. I asked the above question, because I noticed that the cFileName string in the WIN32_FIND_DATA structure always contained only a filename, even if the pattern contained a path, such as "C:\*". If I sent the file to fopen(), it wouldn't work unless the current directory was C:\.

    It doesn't matter now, though, because I've written my own glob() function using FindFirstFile/FindNextFile, adding a directory extracted from the pattern to each returned file name. Thanks for the help, everyone.
    Easily currected, however. Yes, it returns only the filenames of the directory where you expand wildcarrds. However, you can use _chdir to change the current directory to where you are willing to expand them.

    Anyway, good thing you've managed to solve it.
    Atashi wa juu-yon-sai no onna no ko! Atashi no namae wa Miizuki. Yurushiku ne!
    Nani? Atashi o shinjirimasen desu ka? Baka!
    "You're all doomed! Doomed, I say! Hehe... are we approaching the end of the world?"

    shikata ga kaite aru - "the instructions are written above"
    Need to download GoodN64 or instructions to use it? Need to check if it's a good or bad rom?
    Download: Glide64 | Hacktarux's wrapper

Similar Threads

  1. Replies: 1
    Last Post: August 17th, 2004, 03:48
  2. Dumped texture filenames
    By fatcatfan in forum Dolphin
    Replies: 0
    Last Post: March 2nd, 2004, 22:25
  3. Can I change Microcodes manually?
    By F-3582 in forum Project64
    Replies: 2
    Last Post: November 2nd, 2002, 15:20
  4. how to manually re/uninstall 1964
    By flow`` in forum 1964
    Replies: 3
    Last Post: May 26th, 2002, 23:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •