Skip to content

Instantly share code, notes, and snippets.

@sk89q
Created February 7, 2011 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sk89q/814146 to your computer and use it in GitHub Desktop.
Save sk89q/814146 to your computer and use it in GitHub Desktop.
import re
import os.path
from glob import glob
fn_regex = re.compile(r"^c\.(\-?[a-z0-9]+)\.(\-?[a-z0-9]+)\.dat")
total = 0
to_delete = 0
for f in glob("world/*/*/c.*.dat"):
m = fn_regex.match(os.path.basename(f))
if m:
total = total + 1
x = int(m.group(1), 36)
y = int(m.group(2), 36)
if x * 16 < -1263: # Change x,y here
to_delete = to_delete + 1
os.remove(f)
print "%s,%s" % (x, y)
print "Deleting %d/%d (%.2f%%)" % (to_delete, total, to_delete / float(total) * 100)
@uncovery
Copy link

uncovery commented Feb 7, 2011

thanks for this. Unfortunately I am not really knowledgable in python. Given the risks of faulty deletions (yeah I know I have to backup the map anyhow) it would be great to make this foolproof for use.

Questions:
What do I change to delete all coordinates

  • beyond 1000
  • beyond -1000
  • x and y

it looks to me to change line 16 to the respective number and the x to y, but do I have to change the < to > if the number is positive too?
Command line parameters would be great here!

@sk89q
Copy link
Author

sk89q commented Feb 7, 2011

if x * 16 < -1000 or x * 16 > 1000 or y * 16 < -1000 or y * 16 > 1000:

@sk89q
Copy link
Author

sk89q commented Feb 7, 2011

Oh, I'd remove os.remove(f) and have it do a dry run first, just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment