Hello I want to delete certain content from a folder

1

I have a simple doubt. I have generated some files in different formats (.csv, .txt, etc)

I need to delete some. Specifically all ".csv" and those that end with "h + *. Txt" (with * any integer from 1 to 99).

I've tried this:

for archivos in glob.glob((ruta_carpeta) + '*.csv')
   os.remove(archivos)

I've also tried:

os.remove(ruta_carpeta+'\'+'*.csv')

But it does not work for me Any suggestions Thanks

    
asked by Tercuato 26.01.2018 в 13:54
source

2 answers

1

Try these lines:

import os

files = os.listdir("C:\path") # La ruta la copia tal cual del explorador y añade "\" entre carpetas. el ultimo queda libre sin "\"

for name in files:
    if name.endswith(".csv"):
        print(name)
        os.remove("C:\path\%s" % name) # Igual se copia la ruta y se añade "\%s" al final.

and for txt:

import os

files = os.listdir("C:\path")

for name in files:
    for i in range(100):
        if name.endswith("h" + str(i) + ".txt"):
            print(name)
            os.remove("C:\path\%s" % name)
    
answered by 26.01.2018 / 22:08
source
0

If we assume that we read the columns like this:

my @columnas = split /[,]/, $linea;

then, we remove the last three columns with:

splice @columnas, -3;
    
answered by 26.01.2018 в 14:16