Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: I want to create a batch script which can search for .jpg and .jpeg  (Read 9923 times)

0 Members and 1 Guest are viewing this topic.

akki15623

    Topic Starter


    Rookie

    Re: I want to create a batch script which can search for .jpg and .jpeg
    « Reply #15 on: December 16, 2009, 02:11:26 PM »
    Okay, as the script you did, it's amazing.

    can you do one small change in that, as the script is searching in all drives, can you tell me the code if I want to search only one drive.

    If I want to search only one drive, how to do that??

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: I want to create a batch script which can search for .jpg and .jpeg
    « Reply #16 on: December 16, 2009, 02:15:13 PM »
    %%a in the loop is the drive being searched; so take that out of the loop:

    Code: [Select]
    @echo off
    SETLOCAL EnableDelayedExpansion
    set destfolder=D:\copiedjpegs
    set searchdrive="C:\"
    for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %destfolder%

    and then set destfolder and searchdrive accordingly.
    I was trying to dereference Null Pointers before it was cool.

    akki15623

      Topic Starter


      Rookie

      Re: I want to create a batch script which can search for .jpg and .jpeg
      « Reply #17 on: December 16, 2009, 02:25:31 PM »
      Oh, okay.

      Thanks again, your awesome in this programming dude. Keep it up. 8) ;) :) ;D

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: I want to create a batch script which can search for .jpg and .jpeg
      « Reply #18 on: December 16, 2009, 03:08:23 PM »
      OKay then can yoiu help me with a single drive. Lets take with D Drive, there are few pictures that I need to get copied, will you help me with this please.
      I am glad you asked. The others are helping you with the problems involved in using a for loop. As you can see, they have mentioned some of the problems you're going to come into.
      Here is a very simplified answer that follows. But first, I want to make sure that you do not intend just the simple command that works quite well from DOS.
      XCOPY D: E: /S
      In this very simple command, which you should already know the entire contents of drive D: we'll be copied to drive E.: with all of its subdirectories.
      And the variations of that could select just all the files of a certain type in all the entries on the drive.
      But, since you already knew that, we will assume that is not what you meant. That command to locate all the files of one type on a drive is as follows:
      DIR D:*.jpg /s
      That command will show you all the files of that type in all the directories on that drive. Using this command before you do anything else will help you understand if you have too many files to deal with. We hope we don't get any more than maybe 200 or so files. Going beyond about 200 is so files may present a problem in Windows XP. Also, this command gives you some idea of the size. The command should give you a summary at the end of what the total size is for all the files of that type found on that drive. If we get a number that's up in the gigabyte range we had better be careful about trying to copy this to another directory or another drive, unless we know we have that much space available.
      So my point is, we want to have some restraint and some discipline in what we are doing before we start writing some code. Now let's do something else:
      DIR *. jpg /s /b >newjob.bat
      Here we get a brief directory listing that is sent to a file that we have decided to call "newjob.bat" and part of the contents look like this:
      D:\BaaBaa\BIGJOB.jpg
      D:\BaaBaa\DIRT.jpgexit
      D:\BaaBaa\EbayJob.jpg
      D:\Baby\New\Bras.jpg
      D:\Baby\New\Jho.jpg
      D:\Bart\New\Jho.jpg
      D:\CarAndDog\New\Demo1.jpg
      D:\CarAndDog\New\Demo3.jpg
      D:\Baby\New\Nice.jpg
      D:\Baby\School\Demo1.jpg
      D:\Baby\School\Demo2.jpg
      At this point I will use Notepad to open this file and take a look at it. I am going to replace every instance of "D:" with the replacement "Copy D:" and after that I will replace every occurrence of ".jpg" width ".jpg \alljpg", but before I save the file I need to make some changes. Can you see where I am going to have some duplicate filenames and I need to change these to avoid the conflict.?

      (And besides that, don't forget to make a directory called " \alljpg" at the root.)

      Do you understand what I am doing? Is this computer programming? Yes, it is I'm using the computer to write a program using an editor and my final result will be a batch file that I'm very confident will work right first time. I like it when things were right the first time. This is a case where use this apply the power of the human operator to quickly provide a solution that will avoid a problem that could cause much difficulty later on. Namely, the loss of files or the creation of directories that do not have all the files you want and you don't know which ones are missing.
      This post was done almost entirely with my voice recognition software.

      akki15623

        Topic Starter


        Rookie

        Re: I want to create a batch script which can search for .jpg and .jpeg
        « Reply #19 on: December 16, 2009, 03:32:03 PM »
        Oh, okay...


        Yea your right about that, thanks for the information, I will make sure of this. ;D

        akki15623

          Topic Starter


          Rookie

          Re: I want to create a batch script which can search for .jpg and .jpeg
          « Reply #20 on: December 16, 2009, 03:38:59 PM »
          um... no I don't think so.

          you could zip them via the command-line but the attachment will be huge... and I don't know how to do SMTP/e-mail from batch.


          Well I was searching how to send e-mails, and I came up to that we can send via VBS Script through Outlook.

          This is the code,

          Dim ToAddress
          Dim MessageSubject
          Dim MessageBody
          Dim MessageAttachment

          Dim ol, ns, newMail

          ToAddress = "[email protected]"    ' You can change this to your email address
          MessageSubject = "How to send email with Outlook and Vbscript"
          MessageBody = "This is the Sendmail Body"

          Set ol = WScript.CreateObject("Outlook.Application")
          Set ns = ol.getNamespace("MAPI")
          ns.logon "","",true,false
          Set newMail = ol.CreateItem(olMailItem)
          newMail.Subject = MessageSubject
          newMail.Body = MessageBody & vbCrLf

          ' To Validate the recipient
          Set myRecipient = ns.CreateRecipient(ToAddress)
          myRecipient.Resolve
          If Not myRecipient.Resolved Then
              MsgBox "Unknown Recipient"
          Else
              newMail.Recipients.Add(myRecipient)
              newMail.Send
          End If
          Set ol = Nothing

          I dont no how to use this.....

          By seeing this code, can you help me out bro?

          Or give me some tips how to search on internet.

          as you said if I zip the jpg's it will make huge in size.

          So is there a way that I can zip the JPEGs.

          I mean 10 JPEGs to onezip and another 10 JPEGs to one zip like rthat, is that possible??

          ghostdog74



            Specialist

            Thanked: 27
            Re: I want to create a batch script which can search for .jpg and .jpeg
            « Reply #21 on: December 16, 2009, 04:53:54 PM »
            you can download mailx and send email from the client. I have not used it, but you can try.