Disparo en RAW+JPG, es decir, NEF y JPG. Después de ver a veces cientos de imágenes (usando un programa simple) y borrar los JPG, tengo muchos archivos NEF sobrantes innecesarios. Si hubiera una secuencia de comandos para eliminar cualquier archivo NEF huérfano en el directorio, sería muy útil. Leí una pregunta similar aquí " ¿Cómo eliminar archivos JPG, pero solo si existe el archivo RAW correspondiente? " y la solución presentada con el símbolo del sistema funciona muy bien. Me preguntaba si había uno disponible para mi situación.
Escribí un script en Python para hacer el trabajo por mí. Se llama remove-orphaned-raw-images.py
y lo publiqué en Github .
Básicamente, itera sobre todos los archivos en una carpeta determinada y mueve imágenes sin procesar huérfanas (en mi caso *.CR2
, archivos sin JPEG coincidente) a una carpeta de respaldo. Opcionalmente, puede decirle a la secuencia de comandos que elimine los archivos.
Aquí hay un esquema del algoritmo:
La herramienta le dirá cómo usarla cuando se ejecuta con la opción de ayuda -h
en la línea de comando.
Este problema también me ocurrió, por eso escribí esta herramienta. Estoy usando mi DSLR para tomar imágenes JPEG o RAW+JPEG, nunca solo RAW. Cuando clasifico tomas borrosas o malas, uso los archivos JPEG para echarles un vistazo rápidamente y eliminar las malas. Esto me deja con imágenes RAW sobrantes de las cuales eliminé los archivos JPEG correspondientes (por una razón).
Usando la pregunta que mencionaste: te he escrito un guión
vale aviso! ¡Cuidado con este guión! - HACER UNA COPIA DE SEGURIDAD
1) Cree un archivo bat llamado clean.bat y colóquelo en el directorio con el que desea trabajar
2) Luego ingrese lo siguiente en el archivo bat
mkdir keep
for /f "delims==" %%r in ('dir /b *.jpg') do move "%%~dpr%%~nr.nef" "%CD%\keep\" 2> nul
move *.jpg "%CD%\keep\"
del *.nef
del *.jpg
move "%CD%\keep\*.*" "%CD%\"
rmdir keep
3) Abra el símbolo del sistema como administrador y navegue a la carpeta con clean.bat 4) ejecute clean.bat
Básicamente, el flujo del guión es
¡Por favor, POR FAVOR pruebe esto!
ACTUALIZACIÓN: se realizó un cambio de secuencia de comandos para trabajar con carpetas que tienen espacios en ellas
Aquí está mi secuencia de comandos de python para eliminar cr2 sin jpeg.
Busca recursivamente dentro del directorio actual, ".". Considera todas las imágenes en todas las carpetas.
import os
import sys
#Searches through the current directory, recursively, looking for any raw
#and jpeg files. It enumerates the jpegs it finds, without the extension, and
#then enumerates the raw files it finds. If it finds a raw file for which no
#jpeg exists, then it deletes the raw file.
#
# This WILL NOT WORK, if there are files with repeated file numbers.
# this will NOT be an issue if there's only one camera.
# A dict of filename: (rawpath, jpegpath)
files_seen = {}
for (cur_dir, subdirs, files) in os.walk("."):
for file in files:
fname, fext = os.path.splitext(file)
fext = fext.lower()
if (fext == ".jpg"):
content = files_seen.setdefault(fname, [None, None])
# if it is then filenames have du'ped
assert(content[1] is None)
content[1] = os.path.join(cur_dir, file)
elif (fext == ".cr2"):
content = files_seen.setdefault(fname, [None, None])
assert(content[0] is None)
content[0] = os.path.join(cur_dir, file)
#at the end, we look for raw files without a jpeg,
for key in files_seen:
(raw_path, jpeg_path) = files_seen[key]
if jpeg_path is None:
print("Deleting: %s" % raw_path)
#os.system("pause.exe")
os.unlink(raw_path)
print("Done")
os.system("pause.exe")
Ben Parsons
itai
usuario14216
Nadie