Moving Files On Windows

Problem Moving Files on Windows XP

Page 1 of 1

2 Replies - 2985 Views - Last Post: 17 June 2010 - 09:09 AM Rate Topic: -----

#1 mat.roscoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-November 07

Moving Files On Windows

Posted 16 June 2010 - 05:41 PM

Hey All,

I have written a program that will auto generate C++ headers and source for me and i need to move these files from their current dir (src\Public\Data) to an existing dir (src\Private) and I keep getting errors about files not existing but they are there. Here is my code:

#!/usr/bin/python
import os, string, shutil
from subprocess import Popen, PIPE

SrcDirectory = os.getcwd()
SrcDirectory = SrcDirectory + '\\'
DirList =  os.listdir( SrcDirectory )
FileList = []
sFileList = []

DstDirectory = os.getcwd()
DstDirectory = DstDirectory[:-11]
DstDirectory = DstDirectory + 'Private\\'

os.system( 'cls' )

print '***************************************'
print '*      STARTING COMPILE PROCESS       *'
print '***************************************'

print '\n'

for FileName in DirList:
    iTemp = string.count( FileName, ".txt" )
    if iTemp == 1 : 
        command = "generate " + FileName
        print str( os.system( command ) ) + " : " + FileName
        FileList.append( FileName )
     
print'\n'
print '***************************************'
print '*      STARTING MOVING PROCESS        *'
print '***************************************'
print '\n'
     
for sTemp in DirList:
    iTemp = string.count( sTemp, ".txt" )
    if iTemp == 1 : 
        base, ext = sTemp.split( '.' )
        sFileList.append( base ) 
        
iTemp = 0
Countc = 0        
for sTemp2 in DirList :
    iTemp = string.count( sTemp2, ".cpp" )
    if iTemp == 1 :
        for Temp in sFileList : 
            iTemp2 = string.count( sTemp2, Temp )
            if iTemp2 == 1 :
                src = SrcDirectory + sTemp2
                dst = DstDirectory + sTemp2
                #shutil.copyfile( src, dst )
                shutil.move( src, dst )
                Countc = Countc + 1
                
iTemp = 0
Counth = 0        
for sTemp5 in DirList :
    iTemp = string.count( sTemp5, ".h" )
    if iTemp == 1 :
        for Temp in sFileList : 
            iTemp2 = string.count( sTemp5, Temp )
            if iTemp2 == 1 :
                src = SrcDirectory + sTemp5
                dst = DstDirectory + sTemp5
                shutil.copy2( src, dst )
                Counth = Counth + 1
                shutil.copyfile( src, dst )
                

print '\t' + str( Countc ) + " C++ Source Files Moved"
print '\t' + str( Counth ) + " Header Files Moved"

print '\n'
print '***************************************'
print "*       Compile / Move Complete       *"
print '***************************************' 


And Here is the error i keep getting:

***************************************
*      STARTING COMPILE PROCESS       *
***************************************


0 : Test.cpp


***************************************
*      STARTING MOVING PROCESS        *
***************************************


Traceback (most recent call last):
  File "C:src\Public\Data
    shutil.move( src, dst )
  File "C:\Python25\lib\shutil.py", line 199, in move
    copy2(src,dst)
  File "C:\Python25\lib\shutil.py", line 91, in copy2
    copyfile(src, dst)
  File "C:\Python25\lib\shutil.py", line 46, in copyfile
    fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: 'C:src\Public\Data\Test.cpp' 


Thanks in advance for your help!

Is This A Good Question/Topic? 0
  • +

Replies To: Moving Files On Windows

#2 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: Moving Files On Windows

Posted 16 June 2010 - 06:33 PM

I think one problem is the line that reads

DstDirectory = DstDirectory[:-11]



What are you trying to do here?
Was This Post Helpful? 1
  • +
  • -

#3 mat.roscoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-November 07

Re: Moving Files On Windows

Posted 17 June 2010 - 09:09 AM

View PostMotoma, on 16 June 2010 - 05:33 PM, said:

I think one problem is the line that reads

DstDirectory = DstDirectory[:-11]



What are you trying to do here?


this takes the string that is the pathname to the folder that I am working on and removes the last 11 char's or the equivalent to taking 'Src\Public\Data' and making it 'Src\' Everything seems to work fine beside the deleting ... I can use the copy and make a direct copy from the Src\Public\Data to the Src\Private but I cannot seem to delete or remove any of the files from Src\Public\Data once that is done...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1