Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:29:36+00:00 2026-05-23T17:29:36+00:00

I have written a C++ program that reads in a file and outputs the

  • 0

I have written a C++ program that reads in a file and outputs the file with the same name with slight modifications. Now I need to browse recursively into the directory (of any package) and then create files in a separate directory having same directory structure.

I can browse into the directory by using

@file_list = `find <package directory> -name '*.cpp'`;

And I’m trying to execute my program like this:

foreach (@file_list) {
    # This gives error as sh: other_dir/./lev1/lev2/filename.cpp: not found
    ./myexe $_ other_dir/$_;
}

Previously I had written a shell script which worked good with packages having files in a single directory. The script is as follows:

  1 #!/bin/bash
  2 #echo off
  3 rm -rf demac_dir
  4 mkdir demac_dir
  5 for i in `ls *.h *.cpp`
  6 do
  7 echo processing file ${i} ...
  8 ./main ${i} demac_dir/${i}
  9 done

Now I’m trying to so the same thing with a package (i.e. wxWidgets) which has .cpp and .h files in nested subdirectories. So I wrote the following Perl script (after ysth’s suggestion).

  1 #!/usr/bin/perl -l
  2 use File::Path 'make_path';
  3 use File::Basename 'dirname';
  4
  5 `rm -rf demac_dir`;
  6 `mkdir demac_dir`;
  7 @l1 =  `find . -name '*.h'`;
  8 @l2 =  `find . -name '*.cpp'`;
  9 @l3 =  `find . -name '*.cc'`;
 10 push(@l , @l1, @l2, @l3);
 11 foreach (@l) {
 12   print "processing file $_ ...";
 13   make_path( dirname( "demac_dir/$_" ));
 14   ## `touch touch demac_dir/$_`;
 15   `sudo ./main $_ demac_dir/$_`;
 16 }
 17
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:29:37+00:00Added an answer on May 23, 2026 at 5:29 pm

    Err, you are missing a system() or something there that I presume is in your real code.

    To make the directories you need, try:

    use File::Path 'make_path';
    use File::Basename 'dirname';
    
    foreach (@file_list) {
        make_path( dirname( "other_dir/$_" ) );
        ...
    }
    

    Update: seeing your code, it looks like you are leaving newlines on the end of the filenames, which are probably causing you trouble (though I don’t see why your ./main processor would produce the error you say it does…).

    Add a chomp(@l); before your foreach loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a program that reads in a File object (really an XML
hey guys, beginner here. I have written a program that outputs files to .txt's
I have written a program that will etablish a network connection with a remote
I have a website cgi-bin program that is written in c++. Unfortunately the website
I have a console program written in C# that I am using to send
I have a bash script that runs a simulation program written in Fortran 90,
I have written a program in Java to read in a text file of
I have a daemon that reads a configuration file in order to know where
Question: I have written a console program that uses the SQL server 2005 web
Summary: I have a struct that is read/written to file. This struct changes frequently,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.