mrvain
Goto Top

Batch Schleife funktioniert nicht

Hallo,

ich habe ein Konsolen-Programm gefunden, welches u.A. Fotos verkleinern kann...

Das Programm heißt nconvert.

Nun habe ich eine kleiner Batch Datei erstellt, welche Fotos von einem Ordner in einen anderen kopiert.
Nun möchte ich eine kleine Schleife bauen, damit jedes Foto um 50% verkleinert wird.

Hier der Quellcode:


for /F "tokens=1,2,3 delims=/." %%a in ('date/t') do set date2=%%a-%%b-%%c

set path="C:\!!temp\Fotos verkleinern"
set quelle="C:\!!temp\Fotos verkleinern\1"
set ziel="C:\!!temp\Fotos verkleinern\Fotos"
set neu="C:\!!temp\Fotos verkleinern\Fotos\%date2%"

for %%f in (%neu%\*.jpg) do ("C:\!!temp\Fotos verkleinern\nconvert.exe" -rflag orient -resize 50%% 50%% %%f -o %%f.jpg)



Was ist daran falsch?


[Edit Biber] Beitrag von "Windows" nach "Batch & Shell" verschoben wegen dieser Andeutung des Verfassers im Titel. [/Edit]

Content-Key: 102621

Url: https://administrator.de/contentid/102621

Ausgedruckt am: 28.03.2024 um 12:03 Uhr

Mitglied: bastla
bastla 25.11.2008 um 13:30:00 Uhr
Goto Top
Hallo MrVain!

Vorweg: Die Pfade solltest Du anders festlegen (insbes ist es nicht ratsam, die Systemvariable %path% für andere Zwecke zu "missbrauchen") - etwa so:
for /F "tokens=1,2,3 delims=/." %%a in ('date/t') do set date2=%%a-%%b-%%c  

set "pfad=C:\!!temp\Fotos verkleinern"  
set "quelle=%pfad%\1"  
set "ziel=%pfad%\Fotos"  
set "neu=%pfad%\Fotos\%date2%"  
Damit Deine letzte Zeile funktionieren kann, müssen sich zunächst einmal überhaupt Dateien in %neu% befinden - ist das der Fall (und wie sind sie dort hin gekommen)?

Da (auf jeden Fall) der Pfad Leerzeichen enthält, muss %%f unter Anführungszeichen gesetzt werden.

Zusätzlich müsste sichergestellt sein, dass "nconvert" als Output-Parameter Pfade (und nicht nur Dateinamen) akzeptiert.

Dass die verkleinerten Bilder schließlich "Name.jpg.jpg" hießen, ist vermutlich auch nicht beabsichtigt ...

Grüße
bastla

P.S.: Ist vielleicht Geschmackssache, aber ich würde das Datum eher im Format "JJJJ-MM-TT" zusammensetzen - erleichtert im Fall des Falles eine Sortierung ...
Mitglied: MrVain
MrVain 26.11.2008 um 09:37:14 Uhr
Goto Top
Hallo,

Ja in dem Ordner "neu" befinden sich Daten (soll später der Ordner auf einer Digi-Cam sein)...

Ich meine, dass nconvert kein Inhalt eines Ordners auslesen kann, deswegen wollte ich ja eine Schleife bauen, damit "nconvert" jede Datei/Foto einzeln bearbeitet..
Mitglied: bastla
bastla 26.11.2008 um 10:49:15 Uhr
Goto Top
Hallo MrVain!
Ich meine, dass nconvert kein Inhalt eines Ordners auslesen kann,
Meine Frage ging eher in die Richtung, ob "nconvert" bei der Ausgabe nur den Dateinamen verwenden kann, oder ob auch ein Pfad der Art "C:\!!temp\Fotos verkleinern\Fotos\%date2%\Bildname.jpg.jpg" akzeptiert wird.

Ansonsten noch eine weitere Überlegung: Wo sollen die verkleinerten Bilder gespeichert werden? Derzeit wäre das im Ordner "%neu%" unter dem (etwas ungewöhnlichen) Name "Bildname.jpg.jpg" ...

Grüße
bastla
Mitglied: Biber
Biber 26.11.2008 um 11:15:45 Uhr
Goto Top
@bastla
...unter dem (etwas ungewöhnlichen) Name "Bildname.jpg.jpg" ...
Vielleicht sind es ja Bilder von einem HipHop-Festival... lass Ihm doch seinen Spaß.

@MrVain
für den Rest der mitratenden Gemeinde wäre es ganz hilfreich, wenn Du bitte mal die Parameter-Optionen von "Deiner" NConvert.exe hier postest.
Vielleicht lässt sich die ja mit
NConvert /?
aufrufen und zeigt dann alle dokumentierten Parameter?

Grüße
Biber
Mitglied: MrVain
MrVain 27.11.2008 um 21:38:08 Uhr
Goto Top
NCONVERT v5.10 (c) 1991-2008 Pierre-E Gougelet (Nov 19 2008/15:53:12)
Version for Windows NT/9x/2000/Xp/Vista (All rights reserved)
** This is a freeware software (for non commercial use)

The JPEG code is based in part on the work of the Independent JPEG Group's software.
The PNG code is based in part on the work of the Group 42, Inc.
This software is based in part on compression library of Jean-loup Gailly and Mark Adler

Usage : nconvert.exe [options] file ...

Options :
-quiet : Quiet mode
-info : Display informations only
-fullinfo : Display informations & metadata only
-v[.] : Verbose
-in format : Input format number or -1
-page num : Page/image number
-xall : Extract all images
-multi : Create a multi-page (TIFF/DCX/LDF only)
-npcd num : PCD 0:192x128, 1:384x256, 2:768x512 (default)
-ngrb npic : HP-48 number of grey : 1, 2 or 4 (default : 1)
-no# : # not used for numeric operator
-clipboard : Import from clipboard
-ctype type : Channel Type (Raw)
grey : Greyscale (default)
rgb : Red,Green,Blue
bgr : Blue,Green,Red
rgba : Red,Green,Blue,Alpha
abgr : Alpha,Blue,Green,Red
cmy : Cyan,Magenta,Yellow
cmyk : Cyan,Magenta,Yellow,Black
-corder order : Channel Order (Raw)
inter : Interleaved (default)
seq : Sequential
sep : Separate
-size geometry : Width and height (Raw/YUV)
Geometry is widthxheight+offset
-l file : Use file as filelist
-n start end step : Begin End Step (for image sequence)
-o filename : Output filename
Use # to specify position of numeric enumerator
Use % to specify source filename
Use $ to specify source folder
-out format : Output format name
-D : Delete original picture
-c value : Compression number (default : 0)
PDF : 1 (Fax), 2 (Rle), 3 (LZW), 4(ZIP), 5 (JPEG)
TIFF : 1 (Rle), 2 (LZW), 3 (LZW+Prediction)
4 (ZLIB)
5 (CCITT G3), 6 (CCITT G3-2D), 7 (CCITT G4) only B/W
8 (JPEG) only 24/32 bits
TARGA, Softimage, SGI, PCX, IFF, BMP : 1 (Rle)
-q value : JPEG/PNG/FPX/WIC/PDF quality (default : 100)
-clevel value : PNG Compression level (default : 6)
-i : Interlaced GIF / Progressive JPEG
-icc : Use ICC Profile
-merge_alpha : Merge alpha by using 'transparent color' (32bits)
-transparent value: Transparency index (GIF/PNG)
-transpcolor red green blue: Transparency color (GIF/PNG)
-opthuff : Optimize Huffman Table
-bgcolor red green blue: Background color (for rotate/canvas)
-dpi res_dpi : Set the resolution in DPI
-keepdocsize : Resize bitmap function of the old and new DPI value
-keepfiledate : Keep original file data/time
-keepcspace : Keep original color space if possible
-jpegtrans op : JPEG lossless transformations
rot90 : Rotate 90 degrees
rot180 : Rotate 180 degrees
rot270 : Rotate 270 degrees
exif : Use orientation EXIF tag
vflip : Flip vertical
hflip : Flip horizontal
-jpegcrop x y w h : JPEG lossless crop
-clean value : JPEG Clean Metadata (EXIF/IPTC/...)
1 : Comment
2 : EXIF
4 : XMP
8 : EXIF thumbnail
16 : IPTC
32 : ICC Profile
64 : Other markers
-rmeta : Remove Metadata (EXIF/IPTC/...)
-rexifthumb : Remove EXIF thumbnail
-buildexifthumb : Try to rebuild EXIF thumbnail
-thumb width height : Extract thumbnail
-use_cie : Use CIE Colors (PS/EPS/PDF ghostscript)
-wflag flag : Write flag
os2 : Write OS/2 bmp
gif87 : Write GIF87a
hp49 : Write HP49
-high_res : Load high resolution (Camera RAW)
-ascii : Ascii (PPM)
-one_strip : One strip (TIFF)
-raw_autobalance : Auto balance (Camera RAW)
-raw_camerabalance : Camera balance (Camera RAW)
-raw_autobright : Auto brightness (Camera RAW)
-raw_gamma value : Gamma (Camera RAW), default=0.6
-raw_brightness value : Brighness (Camera RAW), default=0.8
-raw_redscale value : Red scaling (Camera RAW)
-raw_bluescale value : Blue scaling (Camera RAW)
-ilut file : Input LUT file (DPX/Cineon)
-olut file : Output LUT file (DPX/Cineon)
-wmfile file : Watermark file
-wmpos x y : Watermark position
-wmflag flag : Watermark position
top-left, top-center, top-right
center-left, center, center-right
bottom-left, bottom-center, bottom-right

Process :
-32bits : Convert in 32bits
-average size : Average (3,5,7,9,11,13)
-autocrop tol r g b : Auto Crop
-balance r g b : Color balance
-binary dither : Convert in Binary
pattern : Ordered pattern
floyd : Floyd steinberg
halft45 : Halftone 45
halft90 : Halftone 90
nodither : No dithering
-blur percent : Blur (1...100)
-brightness value : Modify brightness (-100...100)
-canvas w h pos : Resize canvas
w h can be percent (ex: -resize 100% 200%)
or #x #y for offset
pos top-left, top-center, top-right
center-left, center, center-right
bottom-left, bottom-center, bottom-right
-conbright value : Modify brightness (-100...100)
-colours num
-colors num : Convert in Indexed Colors (256, 216, 128, 64, 32, 16 or 8)
-contrast value : Modify contrast (-100...100)
-crop x y w h : Crop
-dither : Use dither for conversion (Colors and Grey only)
-deinter k n : De-interlace
k : even or odd
n : dup or int
-edetail : Enhance detail
-eedge percent : Enhance edges (1...100)
-edgedetect type : Edge detect
light/medium/heavy
-efocus : Enhance focus
-emboss : Emboss
-embossmore : Emboss more
-equalize : Equalize
-frestore : Focus restoration
-gamma value : Modify gamma (0.01<->5.0
-gammasat value : Modify gamma (0.01<->5.0
-gauss size : Blur gaussian (3,5,7,9,11,13)
-grey num : Convert in Grey Scale (256, 128, 64, 32, 16, 8 or 4)
-hls h l s : Adjust Hue Lightness Saturation
-lens percent : Lens (1...100)
-levels b w : Levels
-log : Apply logarithmic correction
-maximum size : Maximum filter (3,5,7,9,11,13)
-medianb size : Median Box filter (3,5,7,9,11,13)
-medianc size : Median Cross filter (3,5,7,9,11,13)
-minimum size : Minimum filter (3,5,7,9,11,13)
-mosaic size : Mosaic (1...64)
-negate : Negate
-new bpp w h : Create new bitmap
-noise reduce : Reduce noise
-noise type value
uniform : Add uniform noise
gaussian : Add gaussian noise
laplacian : Add laplacian noise
poisson : Add poisson noise
-normalize : Normalize
-oil size : Oilify (1...16)
-posterize count : Posterize (2...256)
-ratio : Keep the ratio for scaling
-rtype : Type of resampling
quick : Quick resize
linear : Bi-linear (linear)
hermite : Hermite
gaussian : Gaussian
bell : Bell
bspline : Bspline
mitchell : Mitchell
lanczos : Lanczos 3
-rflag : Flag for resizing
incr : Increase only
decr : Decrease only
orient : Follow orientation
-resize w h : Scale width-height
w h can be percent (ex: -resize 100% 200%)
-rotate_flag : Rotate flags
smooth : Use smooth rotate
-rotate degrees : Rotate
-sepia : Sepia
-sharpen percent : Sharpen (1...100)
-shear : Shear
-slice : Slice
-soften percent : Soften (1...100)
-solarize value : Solarize (1...255)
-spread amount : Spread (1...32)
-swap type : Swap component
rbg : RGB->RBG
bgr : RGB->BGR
brg : RGB->BRG
grb : RGB->GRB
gbr : RGB->GBR
-swirl degrees : Swirl (1...360)
-text string : Add a text
-text_font name size : Font name and size
-text_color r g b : Text color
-text_back r g b : Text background color
-text_flag pos : Position of text
top-left, top-center, top-right
center-left, center, center-right
bottom-left, bottom-center, bottom-right
-text_pos x y : Position or offset
-text_rotation degrees : Rotation
-tile size : Tile (1...64)
-truecolors
-truecolours : Convert in True Colors
-xflip : Flip horizontal
-yflip : Flip vertical
-waves wavelength phase amount : Waves
wavelength : (1.0 50.0)
phase : (0.0 360.0)
amount : (0.0 100.0)
Mitglied: MrVain
MrVain 08.12.2008 um 13:46:26 Uhr
Goto Top
Weiß noch jemand Rat??

bzw eine Lösung?
Mitglied: bastla
bastla 08.12.2008 um 22:29:42 Uhr
Goto Top
Hallo MrVain!

Falls Du nur alle Bilder aus dem Ordner "C:\!!!temp\Fotos" verkleinert in "C:\!!!temp\Verkleinert" kopieren wolltest, sollte
nconvert -rflag orient -resize 50%% 50%% -o C:\!!!temp\Verkleinert\%%.jpg C:\!!!temp\Fotos\*.jpg
genügen.

Was "nconvert" nicht zu mögen scheint, ist, wenn der Quellpfad unter Anführungszeichen gesetzt ist - daher sollte
nconvert -rflag orient -resize 50%% 50%% -o "C:\!!!temp\Verkleinert\%%.jpg" C:\!!!temp\Fotos\*.jpg
noch funktionieren, aber
nconvert -rflag orient -resize 50%% 50%% -o C:\!!!temp\Verkleinert\%%.jpg "C:\!!!temp\Fotos\*.jpg"
leider nicht. Wenn allerdings die Bilder direkt von der Kamera kommen sollen, wird der Quellpfad wohl ohnehin keine Leerzeichen enthalten.

Grüße
bastla
Mitglied: MrVain
MrVain 09.12.2008 um 10:17:26 Uhr
Goto Top
Vielen Dank, das klappt soweit !