1

I want to use g.mremove to remove multiple files in my mapset,

import os
import sys
sys.path.append(os.path.join(os.environ['GISBASE'], 'etc', 'python'))
import grass.script as g
import grass.script.setup as gsetup
gisbase = os.environ['GISBASE']
gisdb = 'C:\Users\Heinz\Documents\grassdata'
location = 'newLocation'
mapset = 'TC'
gsetup.init(gisbase, gisdb, location, mapset)

g.run_command('g.mremove', rast = 'b_*')
print g.read_command('g.list', _type='rast')

but the output still has b-beginning files,

*** Remote Interpreter Reinitialized  ***
>>> 
----------------------------------------------
raster files available in mapset <TC>:
acc        b16        b23        b30        b7         bas3       basin_test
b10        b17        b24        b31        b8         bas4       dra
b11        b18        b25        b32        b9         bas5       hbas
b12        b19        b26        b33        bas        bas6       hc
b13        b20        b27        b4         bas1       bas7       str
b14        b21        b28        b5         bas10      bas8       vis
b15        b22        b29        b6         bas2       bas9

raster files available in mapset <PERMANENT>:
hc

----------------------------------------------

How to fix this problem? I am using GRASS 6.4.3, python 2.7.6 under Windows 8.1 x64.


Update#1 I have edited the g.run_command line above to this,

g.run_command('g.mremove', flags = 'f', rast = 'b_*')

the output is the same, then I try to do it in the python shell of the GRASS layer manager, and here are the code and output,

>>>g.run_command('g.mremove', flags = 'f', rast = 'b_*')
0
>>>g.read_command('g.list', _type = 'rast')
----------------------------------------------
raster files available in mapset <TC>:
acc        b16        b23        b30        b8         bas5       hc
b1         b17        b24        b31        b9         bas6       str
b10        b18        b25        b32        bas        bas7       vis
b11        b19        b26        b33        bas1       bas8
b12        b2         b27        b4         bas10      bas9
b13        b20        b28        b5         bas2       basin_test
b14        b21        b29        b6         bas3       dra
b15        b22        b3         b7         bas4       hbas

raster files available in mapset <PERMANENT>:
hc

Still give me irrational outputs.

2

In the list of output rasters from g.list, I don't see any that begin with "b_", so it seems that g.mremove worked fine. What's the problem?

If you want to remove all the rasters that begin with "b" then drop the underscore:

g.mremove -f rast="b*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.