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 9066785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:47:48+00:00 2026-06-16T16:47:48+00:00

I am trying to construct a path for each image defined in images list

  • 0

I am trying to construct a path for each image defined in images list and remove it if it exists,currently am hardcoding path for each image mentioned in imagelist below..is there an easier way to implement this?

import os
import subprocess
from subprocess import check_call,Popen, PIPE

def main ():
    images=['test1.img','test2.img','test3.img']
    ROOT="/local/mnt/workspace"
    target="wc3123"
    #Construct ROOT + "/out/target/product/" + target + "/test1.img 
    #for each image mentioned in imageslist remove if it exist"
    test1= ROOT + "out/target/product/" + target + "test1.ming"
    check_call("rm -rf %s" %test1,shell=True)

if __name__ == '__main__':
    main()
  • 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-06-16T16:47:49+00:00Added an answer on June 16, 2026 at 4:47 pm

    You can iterate over your images list of filenames like so:

    def main ():
        images=['test1.img','test2.img','test3.img']
        ROOT="/local/mnt/workspace"
        target="wc3123"
        for image in images:
            #Construct ROOT + "/out/target/product/" + target + "/test1.img 
            #for each image mentioned in imageslist remove if it exist"
            test1= ROOT + "out/target/product/" + target + "/" + image
            check_call("rm -rf %s" %test1,shell=True)
    

    I recommend a few other cleanups as well, such as using os.unlink to remove the files instead of constructing a string to be passed to the shell (which is unsafe), parameterizing your constants so they can be replaced, and using os.path.join instead of concatenating pathnames:

    import os
    
    def main(images, root='/local/mnt/workspace', target='wc3123'):
        for image in images:
            os.unlink(os.path.join(root, target, image))
    
    if __name__ == '__main__':
        main(['test1.img', 'test2.img', 'test3.img'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to construct a list of bean classes in Java from a
I'm trying to construct a datatype that is essentially a binary tree whose: each
I'm trying to construct a path using a command-line argument in bash. I added
In my program I am trying to construct a filename with a path to
I have a very simple path construct that I am trying to parse with
I am trying to construct a file path in order to read an XSLT
Trying to construct a Request with Network.HTTP.Conduit package. The instructions are: The constructor for
Am trying to construct a simple update query in my model class Model_DbTable_Account extends
I am trying to construct a customized map in raphaeljs , in this i
I am trying to construct a deeply nested associative array but i don't know

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.