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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:06:44+00:00 2026-05-27T05:06:44+00:00

I am using python to read 2 files from my linux os. One contains

  • 0

I am using python to read 2 files from my linux os. One contains a single entry/number ‘DATE’:

20111125

the other file contains many entries, ‘TIME’:

042844UTC
044601UTC
...
044601UTC

I am able to read the files to assign to proper variables. I would like to then use the variables to create folder paths, move files etc… such as:

$PATH/20111125/042844UTC
$PATH/20111125/044601UTC
$PATH/20111125/044601UTC

and so on.

Somehow this doesn’t work with multiple variables passed at once:

import subprocess, sys, os, os.path
DATEFILE = open('/Astronomy/Sorted/2-Scratch/MAPninox-DATE.txt', "r")
TIMEFILE = open('/Astronomy/Sorted/2-Scratch/MAPninox-TIME.txt', "r")
for DATE in DATEFILE:
    print DATE,
for TIME in TIMEFILE:
    os.popen('mkdir -p /Astronomy/' + DATE + '/' TIME) # this line works for DATE only
    os.popen('mkdir -p /Astronomy/20111126/' + TIME) # this line works for TIME only
    subprocess.call(['mkdir', '-p', '/Astronomy/', DATE]), #THIS LINE DOESN'T WORK

Thanks!

  • 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-27T05:06:44+00:00Added an answer on May 27, 2026 at 5:06 am

    I would suggest using os.makedirs (which does the same thing as mkdir -p) instead of subprocess or popen:

    import sys
    import os
    DATEFILE = open(os.path.join(r'/Astronomy', 'Sorted', '2-Scratch', 'MAPninox-DATE.txt'), "r")
    TIMEFILE = open(os.path.join(r'/Astronomy', 'Sorted', '2-Scratch', 'MAPninox-TIME.txt'), "r")
    
    for DATE in DATEFILE:
        print DATE,
    
    for TIME in TIMEFILE:
        os.makedirs(os.path.join(r'/Astronomy', DATE, TIME))
    
        astrDir = os.path.join(r'/Astronomy', '20111126', TIME)
        try
            os.makedirs(astrDir)
        except os.error:
            print "Dir %s already exists, moving on..." % astrDir
        # etc...
    

    Then use shutil for any cp/mv/etc operations.


    From the os Docs:

    os.makedirs(path[, mode])
    Recursive directory creation function. Like mkdir(), but makes all
    intermediate-level directories needed to contain the leaf directory.
    Raises an error exception if the leaf directory already exists or
    cannot be created. The default mode is 0777 (octal). On some systems,
    mode is ignored. Where it is used, the current umask value is first
    masked out.

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

Sidebar

Related Questions

How to Write/Read a file to/from a network folder/share using python? The application will
Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I found that you can't read from some sites using Python's urllib2(or urllib). An
Using Python, how would I go about reading in (be from a string, file
I'm looking for information on how to read GnuCash files using python. I have
I'm trying to have python read some lines of text from a file and
I'm using Python 2.6 and PyGTK 2.22.6 from the all-in-one installer on Windows XP,
A Python program I'm writing is to read a set number of lines from
I need to read selected files, matching on the file name, from a remote
Possible Duplicate: comparing contents of two files using python I have a file name

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.