MCPcopy Index your code
hub / github.com/RetiredWizard/PyDOS / delFiles

Function delFiles

PyDOS.py:397–421  ·  view source on GitHub ↗
(Dir,File,Recurs,removDirs)

Source from the content-addressed store, hash-verified

395 return
396
397 def delFiles(Dir,File,Recurs,removDirs):
398 for _dir in os.listdir(pFmt(Dir,False)):
399 if _match(File,_dir[:wldCLen]):
400 if File == "*" or File == "*.*" or _dir == _dir[:wldCLen]:
401 if aFile(Dir+_dir):
402 try:
403 os.remove(Dir+_dir)
404 print((Dir+_dir).replace('/',('\\' if envVars.get('DIRSEP','/') == '\\' else '/')),"deleted.")
405 except Exception as err:
406 print(f"Unable to delete: {Dir}{_dir}, Exception: {err}")
407 break
408 elif Recurs:
409 delFiles(Dir+_dir+sep,'*',Recurs,removDirs)
410 if removDirs:
411 if os.getcwd() == Dir+_dir:
412 os.chdir("..")
413 try:
414 os.rmdir(Dir+_dir)
415 except Exception as err:
416 print(f"Unable to remove: {Dir}{_dir}, Exception: {err}")
417 break
418 else:
419 print("Unable to delete: "+Dir+_dir+". Filename too long for wildcard operation.")
420 elif Recurs and not removDirs and not aFile(Dir+_dir):
421 delFiles(Dir+_dir+sep,File,Recurs,removDirs)
422
423 def setCondCmd(args,i,condResult):
424 condCmd = ""

Callers 1

PyDOSFunction · 0.85

Calls 3

getMethod · 0.80
pFmtFunction · 0.70
_matchFunction · 0.70

Tested by

no test coverage detected