

InterviewSolution
1. |
Solve : Batch file to save photos into folders? |
Answer» I would appreciate any help to speed up a very mundane task. the 3 that moved were .jpg whilst the remainder were .JPG does the case make any difference? it would appear so. Change the line: Code: [Select] If fso.GetExtensionName(fs) = "jpg" Then to: Code: [Select] If lcase(fso.GetExtensionName(fs)) = "jpg" Then I did TRY: If fso.GetExtensionName(fs) = "jpg" or "JPG" Then but it didnt recognise the string JPG.....Well ...... I would like to say a big thank you to sidewinder for his time and effort and for BC_Programmer for his fine tuning........ Many thanks..... All i have to do now is decifer how the beast works.... This could work...not quite sure...it depends on the camera. @echo off setlocal enabledelayedexpansion for /f "skip=5 tokens=1,5" %%A in ('dir /t:c *.jpg') do ( echo Date --- %%A echo File --- %%B if not "%%B"=="" if not "%%B"=="free" ( set filedate=%%A set filedate=!filedate:/=-! if not exist !filedate! md !filedate! copy %%B !filedate! ) ) pause Seems to work for me. I just felt like making an all-batch solution.Quote from: eddie.ceri on April 07, 2010, 04:40:27 PM I did try: That isn't proper syntax. the "Or" operator only works on Booleans or numeric variables. in order for it to work here you'd need to use: Code: [Select]If fso.GetExtensionName(fs) = "jpg" or fso.GetExtensionName(fs)="JPG" Then However, it still wouldn't work for mixed case, like jPg or Jpg or JPg, etc. using lcase or ucase to convert the case before COMPARISON, however, fixes that. *Note: Previously, me and Geek-9pm, another member, got in a rather heated debate with regards to this particular usage. my stance was that it was best to use StrComp() to compare strings,rather then case conversions. this was based on the fact that StrComp() would recognize combined glyphs such as the combined "AE" character properly being matched to the actual two characters, AE. However, it would appear, from what I've read in the meantime regarding StrComp, that while this would work, it is slower (another incorrect contention I held was that the StrComp() method was faster). StrComp() is designed for comparing strings for sorting algorithms; this is why it returns a value indicating the sort order of the two items. Therefore, if geek-9pm is reading this, I was WRONG Quote from: Helpmeh on April 07, 2010, 04:47:57 PM This could work...not quite sure...it depends on the camera. No, that won't work. "Date Picture Taken" is an EXIF attribute, and while the actual date of the picture can be used for this it breaks down when that file is copied or moved, whereas the EXIF data stays intact. I have just test run the .vbs file and it works great ........... there are a few ponts that i didnt think would be a problem but might cause issues..... 1. If a file with the same name is already in that folder (probably the same file anyway) the WHOLE routine doesnt run it creates an error message "Microsoft VBScript runtime error: File already present" which is common sense i suppose. 2. What i would prefer if it didnt copy it and allowed me to sort it out manually later but carried on with the rest of the jpegs.Quote from: eddie.ceri on April 07, 2010, 04:59:14 PM I have just test run the .vbs file and it works great ........... Good idea. I just added an "On Error Resume Next" statement. Code: [Select]folderName = "c:\Pictures" 'check for valid directory Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(folderName) Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(folderName) Set fc = f.Files For Each fs In fc If fso.GetExtensionName(fs) = "jpg" Then Set objFolderItem = objFolder.ParseName(fs.Name) strValue = objFolder.GetDetailsOf(objFolderItem, 25) If strValue <> "" Then newYY = DatePart("yyyy", strValue) newMM = DatePart("m", strValue) If newMM < 10 Then newMM = "0" & newMM newDD = DatePart("d", strValue) If newDD < 10 Then newDD = "0" & newDD newFolder = "c:\" & newYY & "_" & newMM & "_" & newDD 'check for valid drive and path If Not fso.FolderExists(newFolder) Then fso.CreateFolder(newFolder) End If On Error Resume Next fso.CopyFile fs.Path, newFolder & "\" End If End If Next It is also possible to create a logfile of the files that were missed.That worked great....... The log would be good, I have removed any duplicate jpgs by using the "Easy duplicate finder" application. Many thanks for your time and effort BC_Programmer Quote from: eddie.ceri on April 07, 2010, 02:10:01 PM I would appreciate any help to speed up a very mundane task. you can download jpeg tools like jhead for example, and then run your photos with jhead using for loop and grab the images creation date/time, do some manipulation with the date/time to the format you want, and then use mkdir to create directories etc etc... |
|