im trying to copy all files in a directory to another directory but i cant seem to figure it out, ive tried to create a text file with all the names of the files in it:
dirlist = open(“fost_serv_both/fost_1/dirlist.txt”, “r”)
for line in dirlist:
copytree("fost_serv_both/fost_1/" + line.rstrip(), dir + line)
but it errors and if i leave the rstrip() off it keeps adding a /n and it says cant find file or something. I know i can explicitly copy every file one at a time (theres over a hundred of them) but id like to make it simpler if i can
by the way, this has nothing to do with wxPython.
try the python standard library shutil module.
seem to figure it out, ive tried to create a text file with all the names of
the files in it:
why not os.listdir() ?
but it errors and if i leave the rstrip() off it keeps adding a /n
It's not adding a "/n", it's leaving there. That's what's in your text file. Python leaves in on in a readline() call for good reason.
also, what about wild cards and the shell?
on a *nix command line:
cp The/Old/Directory/* The/New/Directory/
Windows (Dos box) has similar syntax.
You can use wild cards with the glob module too.
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
your right this dosent have anything to do with wxpython. i really diddnt put much thought into it being a python issue (instead of a wxpython issue). I know i can do it with shell commands but i was hoping to make it more cross platform and generic, ill have to look into the os.listdir() thing. thanks for the input
···
On 5/5/06, Christopher Barker Chris.Barker@noaa.gov wrote:
by the way, this has nothing to do with wxPython.
try the python standard library shutil module.
seem to figure it out, ive tried to create a text file with all the
names of
the files in it:
why not os.listdir() ?
but it errors and if i leave the rstrip() off it keeps adding a /n
It’s not adding a “/n”, it’s leaving there. That’s what’s in your text
file. Python leaves in on in a readline() call for good reason.
also, what about wild cards and the shell?
on a *nix command line:
cp The/Old/Directory/* The/New/Directory/
Windows (Dos box) has similar syntax.
You can use wild cards with the glob module too.
-Chris
–
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Also see os.walk() (to get file/path names), os.rename() (if you want to
rename stuff), or as Christopher suggested, shutil.copytree().
- Josiah
···
"justin mcguire" <jherrico@gmail.com> wrote:
your right this dosent have anything to do with wxpython. i really diddnt
put much thought into it being a python issue (instead of a wxpython
issue). I know i can do it with shell commands but i was hoping to make it
more cross platform and generic, ill have to look into the os.listdir()
thing. thanks for the input
On 5/5/06, Christopher Barker <Chris.Barker@noaa.gov> wrote:
>
> by the way, this has nothing to do with wxPython.
>
> try the python standard library shutil module.
>
> > seem to figure it out, ive tried to create a text file with all the
> > names of
> > the files in it:
>
> why not os.listdir() ?
>
> > but it errors and if i leave the rstrip() off it keeps adding a /n
>
> It's not adding a "/n", it's leaving there. That's what's in your text
> file. Python leaves in on in a readline() call for good reason.
>
> also, what about wild cards and the shell?
>
> on a *nix command line:
>
> cp The/Old/Directory/* The/New/Directory/
>
> Windows (Dos box) has similar syntax.
>
> You can use wild cards with the glob module too.
>
> -Chris
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker@noaa.gov
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>