Thread: wildcard file open

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    486

    wildcard file open

    I have a bunch of folders I need to open in sequence and extract relevent data. They look like this:

    Code:
    20090810_13h25_491_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam8.9_I7e13
    20090810_13h25_492_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam9.0_I7e13
    20090810_13h25_493_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam9.1_I7e13
    20090810_13h25_494_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam9.2_I7e13
    20090810_13h25_495_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam9.3_I7e13
    20090810_13h25_496_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam9.4_I7e13
    20090810_13h25_497_impact_cross_section_HS_motion_test_dt00.001000as_nbions000002_S0I0T0R0_potGaussianDistribution_iTE0.2_ImParam9.5_I7e13
    I don't care about the first part, only the last few bits: potGaussianDistribution_iTE0.2_ImParam9.3_I7e13

    Using wildcards, is there a way to iterate through these one after the other?

    Basically, I just want to wildcard out the first 3/4 of each folder name.Will a simple * work like in bash? *is hopeful*

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    You are wanting to do this in C???? On what platform????

    If you are in *nix, then you could pass all these in via the command line and parse through each that way.

    If you aren't wanting to do this in C, then I'd suggest doing a bash script using ls, grep, awk, and sed for starters.
    Code:
    SEDINFO_HEAD="20090810_.*potGaussian"
    for i in `ls | sed s/${SEDINFO_HEAD}/potGaussian//` ; do
            echo $i
    done
    WARNING: I haven't tested the above.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Bash "typeglobs" such as the wildcard are not native in C.

    You have a few choices, eg, using a scanf type template, and/or other string functions like strstr* and strcmp.

    There is regex.h, which will definitely give you the most options, but is also the most hassle and is probably not the most efficient way to go unless there is no other way. I think regexp = power + expense. However, if you have to do a varied bunch of string parsing like this in the program, once you have a regexp function set up you will be able to do all of it easily.

    Judging from your example, if all the files are really like that -- the first part of the line always the same length -- why not just use a fixed offset into the line? That's the least flexible, but also the easiest and most efficient way.

    * check up on strstr() first.
    Last edited by MK27; 08-10-2009 at 11:51 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    486

    You are wanting to do this in C???? On what platform????
    lol not anymore. Now I am wanting to do this in bash.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by KBriggs View Post
    lol not anymore. Now I am wanting to do this in bash.
    Here's a good page about that:
    Manipulating Strings
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM