Hello, I am writing a script that will organize all the code in the
given directory. Well, currently I have it make dir's with something
like:
os.mkdir("C")
os.mkdir("Python")
os.mkdir("ASM")
And so on. That is not very practical, and I wish to change it. I was
wondering if there were any other methods to which I could do this, I
was thinking maybe I could put the dir names in a dictionary then have
something like:
os.mkdir(thedictname)
This doesn't sound like it would work, maybe with a bit of tweaking to
my idea. So, anyone that has any idea's on how I could do this...that
would be great...
Thanks for your help.
--
gurusnetwork.org
Gurus'Network - Are you a guru? 6 12320
yawgmoth7 wrote: And so on. That is not very practical, and I wish to change it. I was wondering if there were any other methods to which I could do this, I was thinking maybe I could put the dir names in a dictionary then have something like: os.mkdir(thedictname)
Why not use a loop?
dirs = ['ASM', 'C', 'Python']
for dir in dirs:
os.mkdir(dir)
yawgmoth7 wrote: Hello, I am writing a script that will organize all the code in the given directory. Well, currently I have it make dir's with something like:
os.mkdir("C") os.mkdir("Python") os.mkdir("ASM")
And so on. That is not very practical, and I wish to change it. I was wondering if there were any other methods to which I could do this, I was thinking maybe I could put the dir names in a dictionary then have something like: os.mkdir(thedictname)
This doesn't sound like it would work, maybe with a bit of tweaking to my idea. So, anyone that has any idea's on how I could do this...that would be great...
Thanks for your help. -- gurusnetwork.org Gurus'Network - Are you a guru?
Assuming something in the standard library doesn't do this already
(shutils, os, os.path)
import os
def mkdirs(pths):
for pth in args:
os.mkdir(pth)
mkdirs(["C","Python, "ASM"])
Is that what you mean?
yawgmoth7 wrote: Hello, I am writing a script that will organize all the code in the given directory. Well, currently I have it make dir's with something like:
os.mkdir("C") os.mkdir("Python") os.mkdir("ASM")
And so on. That is not very practical, and I wish to change it. I was wondering if there were any other methods to which I could do this, I was thinking maybe I could put the dir names in a dictionary then have something like: os.mkdir(thedictname)
This doesn't sound like it would work, maybe with a bit of tweaking to my idea. So, anyone that has any idea's on how I could do this...that would be great...
Thanks for your help. -- gurusnetwork.org Gurus'Network - Are you a guru?
Assuming something in the standard library doesn't do this already
(shutils, os, os.path)
import os
def mkdirs(pths):
for pth in pths:
os.mkdir(pth)
mkdirs(["C","Python, "ASM"])
Is that what you mean?
yawgmoth7 wrote: os.mkdir("C") os.mkdir("Python") os.mkdir("ASM")
And so on. That is not very practical, and I wish to change it. I was wondering if there were any other methods to which I could do this, I was thinking maybe I could put the dir names in a dictionary then have something like: os.mkdir(thedictname)
For what do you need a dictionary? A list or a set should suffice:
[os.mkdir(d) for d in "C Python ASM".split()]
If some of these directories could already exist, this may be safer:
for d in "C Python ASM".split():
try:
os.mkdir(d)
except OSError:
pass
Another possibility is the following:
os.system("mkdir C Python ASM")
-- Chris
Or os.makedirs():
#v+ import os print os.makedirs.__doc__
makedirs(path [, mode=0777])
Super-mkdir; create a leaf directory and all intermediate ones.
Works like mkdir, except that any intermediate path segment (not
just the rightmost) will be created if it does not exist. This is
recursive.
#v-
Cheers,
--
Klaus Alexander Seistrup
Copenhagen, Denmark http://seistrup.dk/
Klaus Alexander Seistrup wrote: Or os.makedirs():
Although that may or may not do what the OP wants. I was assuming she
was trying to produce a directory structure like:
/dir/C/
/dir/ASM/
/dir/Python/
os.makedirs() produces a directory hierarchy, like:
/dir/C/ASM/Python/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Befuddled |
last post by:
Forgive me, this is probably a very simple problem, but it's new to
me.
When I attempt to make php 4.3.8, it exits, and I believe the relevant
message is:
libtool: link: cannot find the library...
|
by: Bernard Fields |
last post by:
Greets, all.
As the title suggests, I'm trying to make a maze. Specifically, it's a
top-down, 2-d maze, preferably randomly generated, though I'm willing to
forego that particular aspect as...
|
by: Jean-François Doyon |
last post by:
Hello,
I'm using MetaClasses to create classes.
How do I make these new classes "globally" available?
I probably just have to assign them to something magic, but I can't seem to
figure out...
|
by: Ron Nolan |
last post by:
Re: Access 2000
According to the help, to loop through a folder, you use code like
this:
' Returns filename with specified extension. If more than one *.ini
' file exists, the first file...
|
by: Alexander Farber |
last post by:
Hi,
I have a UNIX-server written in C, which exchanges messages
with Java clients. In the message the 1 byte is its length,
the 2nd a player number and the 3rd byte is an event id:
/* 0....
|
by: Pavel |
last post by:
Hello.
I am trying to make a folder compressed and failing miserably. Below
are three ways that I tried to make it compressed, all of them compile
and run w/o any problems, but the folder is...
|
by: Nathan Sokalski |
last post by:
I have a form that allows the user to upload a file. Even though <input
type="file" runat="server"> is intended to have the user choose the file
using the browse button, it still allows them to...
|
by: nothing1 |
last post by:
Here is my code and what it does is create a page for every directory with the contents of choice.
Its been working on all letters except "u" I can't seem to figure it out.
Does someone see the...
|
by: Rafe |
last post by:
Hi,
I'm working within an application (making a lot of wrappers), but the
application is not case sensitive. For example, Typing obj.name,
obj.Name, or even object.naMe is all fine (as far as...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |