UNIX question to the experts

Posted on
Thu Sep 01, 2016 8:02 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

UNIX question to the experts

I would like to delete a set of files that look like

path/commonName-i

path and common name can contain space or special characters (umlauts etc)

if p= path and x = commonName I would like to do
Code: Select all
subprocess.Popen("rm "+p+x+"*",shell=True)

I works if there are no spaces or special characters, but
that does not work if there a blanks in the name. if I add ' around p+x the "*" does not work.

I also found that eg umlauts in the file name are different than in the unix shell.
I am using the same variables to create --
Code: Select all
f=open("'"p+x+"-1'","w")
-- and delete the files.
Code: Select all
subprocess.Popen("rm '"+p+x+"-1'",shell=True)
states file does not exist .. any Unicode or utf8 suggestions?

Karl

Posted on
Thu Sep 01, 2016 9:01 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: UNIX question to the experts

Thought 1: use a python script and use os.remove()

Thought 2: maybe this:
Code: Select all
find /path/to/dir/* -exec rm {} \;

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Sep 01, 2016 7:48 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: UNIX question to the experts

This one works:

Code: Select all
            files = os.listdir( commonPath )  # path to the directory
            for ff in files:
                #indigo.server.log(unicode(ff) )
                for TTI in range(noOfTimeTypes):
                    if ff.find(u"-"+binTypeFileNames[TTI]+u"-") >-1:  # this are  the common strings in the filenames and they are unique
                        try:
                            xx=os.remove(commonPath+ff)
                        except:
                            indigo.server.log("failed "= unicode(xx) )


will delete any file (also w space ä º characters) with string "-commonString-" in directory commonPath

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests