Select to view content in your preferred language

\f (form-feed) interfering with file names in code

2232
3
07-03-2012 08:48 AM
by Anonymous User
Not applicable
Original User: MCline19

I have a functioning code block, which utilizes a list to input file names to be processed.  I have enountered an issue I do not know how to resolve.  The list of files I am currently trying to process has "\f" within the file names (see list code below). 

sdeFiles = ['G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.Apartments','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.CE_Areas','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.Fire_Grid','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.Fire_Stations','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.Mall','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.PostOak_Mall','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.PrePlan\fire.FIRE.Buildings','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.PrePlan\fire.FIRE.Hydrants','G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.PrePlan\fire.FIRE.Points']


The presence of "\f" within the file name returns errors when attempting to use the file, because it changes the file name to appear like the following example:  'G:\\Department Projects\\Fire\\Fire DA_DC.sde\x0cire.FIRE.Apartments'

I have looked up the issue.  /f has something to do with form-feed and moving printing positions. 

I need to find someway around this.  I have tried changing the file name in my list to contain // rather than \; however, this returned an error stating the file did not exist. 

Any ideas or solutions would be greatly appreciated.  THANKS!
0 Kudos
3 Replies
by Anonymous User
Not applicable
Original User: NobbirAhmed

If you want to use the backslash as path separator then make your string a raw string just by putting a 'r' in front like this:

r'G:\Department Projects\Fire\Fire DA_DC.sde\fire.FIRE.Apartments'
0 Kudos
curtvprice
MVP Alum
Two helpful links

0 Kudos
by Anonymous User
Not applicable
Original User: MCline19

Thanks!  Both responses help.  I do have 1 more question though. 

When my script is complete, I need it to delete some temporary files that were created in the process; however, I am getting an error.  When my script runs, it opens the final files it creates in ArcMap and in order to delete the temporary files, I think I need to close the opened files.  My script is below, with the delete portion and errors being at the bottom:

import arcpy
sdeFiles = ['G:\Department Projects\Development Services\Dev Services DA_DC.sde\dev_services.DEVSERV.Aerial_monuments1994']
print ("Beginning .sde to .shp file converstion")
for x in sdeFiles:
 n = x.split('.')[-1]
 arcpy.FeatureClassToShapefile_conversion(x,'G:\GISAdmin\SDE_Backups\NewTempShapefiles')
 extension = n + '.shp'
 newFile = 'G://GISAdmin//SDE_Backups//NewTempShapefiles//' + extension
 backupFile = 'G://GISAdmin//SDE_Backups//BackupFiles//' + extension
 print ("Beginning feature compare")
 if arcpy.Exists(backupFile):
  arcpy.FeatureCompare_management(newFile,backupFile, 'FID')
 else: 
  arcpy.CopyFeatures_management(newFile,backupFile)
  print ("Beginning backup")
  if newFile == backupFile: 
   pass 
  elif arcpy.Exists(backupFile):
   arcpy.management.Delete(backupFile) and arcpy.CopyFeatures_management(newFile,backupFile)
print ("Backup complete")
for x in sdeFiles:
 arcpy.management.Delete(x)
 #Getting error 000464: Cannot get exclusive schema look.  Either being edited or in use by another applicaiton.  Failed to execute (Delete).
print "Temporary files deleted"



Any advise on how to close and delete would be great!  Thanks!
0 Kudos