Newby Question: os.rename

Kevin Bass KBASS1 at nc.rr.com
Mon Sep 2 12:07:21 CEST 2002


"Kevin Bass" <KBASS1 at nc.rr.com> wrote in message
news:AcGc9.68214$Xa.3523883 at twister.southeast.rr.com...
> I am attempting to create an archive function within my program. This
> function should create a directory with a timestamp name (such as
> /home/oracle/data/20020831) on the fly, list the contents of a current
> directory then place the contain from the previous directory into the
newly
> created directory.
>
> The newly created directory with the timestamp name is being created and
the
> list of files from the current directory has been retrieved but my problem
> comes when moving the files to the newly created directory. I am trying to
> achieve this tasks with os.rename but find it difficult to get the command
> to recognize the new directory and place the files into it.
>
> I have attempted to get os.rename to recognize the 'archloc' variable that
> contains the name of the newly created directory but that did not work.  I
> also tried to join the newly created directory with the file names then
send
> it through os.rename and that did not work either.
> What am I doing wrong? Thanks!! (My code is listed below)
>
>
> def archive_data(archive):
>
>    the_date = strftime("%Y%m%d")
>    archloc = ('/home/oracle/data/' + the_date)
>    os.mkdir(archloc)
>
>    if archive == 'yes':
>       for file in os.listdir('/home/oracle/data'):
>          file2 = os.path.join(archloc, file)
>          #print file2
>    os.rename(r'/home/oracle/data/' + file, file2)
>
> Kevin
>
>
>
>

I have figured it out. Thanks!





More information about the Python-list mailing list