Skip to main content
Question

Create directory with Python

  • Aug 20, 2013 9:00 AM UTC
  • 7 replies
  • 108 views

farfar
Contributor
Forum|alt.badge.img+12
Hi,

 

I create a fmw that : 1. create a directoy with the same name of zip file, 2. move the zip file to this directory. 

 

this fmw works fine withe if the name of file is note a numeric (like : toto.shp.zip, => OK but with another file that has only numeric name : 1.shp.zip => KO). 

 

With FME Desktop it works fine for both cases.

 

If i run it with FME SERVER, there is an error : 

 

 

54 WARN 0.2 1.3 2013-08-20 10:49:50 Python Exception : [Errno 2] No such file or directory: '\\\\\\\\1.shp.zip' 55 ERROR 0 1.3 2013-08-20 10:49:50 Error encountered while calling function `processFeature'

 

No more details for this error. 

 

 

Any help?

 

Thanks an advance.

 

 

Farfar
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

takashi
Celebrity
  • Aug 20, 2013 10:07 AM UTC
Hi Farfar,

 

 

Path delimiter may cause the error. How about using / (slash) instead of \\ (back slash)?

 

 

Takashi

farfar
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • Aug 20, 2013 10:12 AM UTC
Hi Takashi,

 

I use "join" to have a directory path. 

 

this my python script : 

 

def processFeature(feature):          #create work folder     fmebasename = feature.getAttribute("fme_basename")     workfolder = os.path.join(FME_MacroValues['workFolder'],fmebasename)          if not os.path.exists(workfolder):         os.makedirs(workfolder)     else:         #delete files ito work folder         os.chdir(workfolder)         filelist = glob.glob("*.shp.zip")         for f in filelist:             os.remove(f)          # move zip file into work folder     filename = fmebasename+".shp.zip"          fmedataset =  feature.getAttribute("fme_dataset")                end = fmedataset.find(fmebasename)        src_file = fmedataset[0:end]              src_file = os.path.join(src_file, filename)          dst_file = os.path.join(workfolder, filename)     shutil.move(src_file, dst_file)              pass

 

 

Thanks 

 

Farfar

farfar
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • Aug 20, 2013 12:29 PM UTC
Hi,

 

I use my script in my previous message, i replace  :

 

workfolder = os.path.join(FME_MacroValues['workFolder'],fmebasename) 

 

by : 

 

workfolder = FME_MacroValues['workFolder'] + "\\\\" + fmebasename.

 

 

And i still have the problem. 

 

 

Any Help? 

 

Thanks.

 

Farfar

takashi
Celebrity
  • Aug 20, 2013 1:17 PM UTC
Was a slash "/" also ineffectual?

 

 

Takashi

farfar
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • Aug 20, 2013 1:22 PM UTC
Hi Takasha,

 

I tested both of "//" ,  "\\\\" and "join" function and i've a same error. But if i use a non numeric file name, it works.

 

 

Farfar

 

 


david_r
Celebrity
  • Aug 20, 2013 1:54 PM UTC
Hi,

 

 

the simplest might be to insert

 

 

print "src_file:", src_file

 

 

or something like that at the end of your script. This  will print to the FME log window the actual values generated by your script. Let us know what it says so that we can try and help you find the error.

 

 

David

farfar
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • Aug 20, 2013 3:15 PM UTC
Hi David,

 

Thank you for your idea. The pb is the extract the value of "src_file" : the fme_dataset has a value that is in the path, so to split the path, its wrong. 

 

Example : 

 

   print "fmebasename:", fmebasename

 

    fmedataset =  feature.getAttribute("fme_dataset")  

 

    print "fmedataset :",fmedataset      end = fmedataset.find(fmebasename)        print "fmedataset:",fmedataset     print "end:",end     src_file = fmedataset[0:end]

 

     print "src_file:", src_file

 

 

The result is : 

 

  fmebasename = 1

 

  fmedataset : \\\\\\\\1.shp.zip\\1.shp

 

  end:,2                  ==> WRONG

 

  src_file: \\\\1.shp.zip

 

 

I find now the origin of my error and fix it.

 

Thank you

 

 

Farfar