CrazyEngineers
  • Necessity is the Mother of Invention - Batch Job

    Updated: Oct 23, 2024
    Views: 1.4K
    Hey CEans,

    I would like to share something interesting happened just now, when I wanted to do something! 😀 This is one solid proof that if you have the will to do, you will find a way somehow! 😀

    So, what did I do? I was downloading about 25 files for some work of mine and I had to organise them into folders, under my Downloads folder. Each file has a description in a URL and the file itself has a unique name. Lets consider there are three files for now.
    File #1
    File:      NetBeans IDE
    File Name: netbeans-7.1-ml-php-windows.exe
    File URL:  https://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php
     
    File #2
    File:      Eclipse IDE
    File Name: eclipse-jee-indigo-SR1-win32.zip
    File URL:  https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr1
     
    File #3
    File:      Aptana Studio
    File Name: Aptana_Studio_3_Setup_3.0.8.exe
    File URL:  https://www.aptana.com/products/studio3/download
    Now I want them in a folder structure this way:
    /NetBeans IDE
    --/netbeans-7.1-ml-php-windows.exe
    --/Link.txt (Content: https://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php)
    /Eclipse IDE
    --/eclipse-jee-indigo-SR1-win32.zip
    --/Link.txt (Content: https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr1)
    /Aptana Studio
    --/Aptana_Studio_3_Setup_3.0.8.exe
    --/Link.txt (Content: https://www.aptana.com/products/studio3/download)
    Could anyone guess what did I do? Remember, there are 25 files! 😀 I did it in about 3 minutes!!! 😀
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • PraveenKumar Purushothaman

    MemberFeb 6, 2012

    Okay CEans, I just did this. I opened Microsoft Excel and at first, wrote down the URLs and names of the folders. The sheet looked this way:
    +-----------------------------------------------------------------+
    | https://netbeans.org/d...dows&lang=en&option=php | NetBeans IDE  |
    | https://www.eclipse.org/d...developers/indigosr1 | Eclipse IDE   |
    | https://www.aptana.com/products/studio3/download | Aptana Studio |
    +-----------------------------------------------------------------+
    Then I created the directories for the same using this:
    mkdir NetBeans IDE
    mkdir Eclipse IDE
    mkdir Aptana Studio
    After that I browsed through the Internet to find how am I supposed to create a text file with some contents, using command line. I got this piece of info:
    echo Content > filename
    echo Hello World > New.txt
    This I thought of making use and tried to rearrange the Excel sheet this way:
    +-------------------------------------------------------------------------------------------+
    | echo | https://netbeans.org/d...dows&lang=en&option=php | > " | NetBeans IDE  | \Link.txt" |
    | echo | https://www.eclipse.org/d...developers/indigosr1 | > " | Eclipse IDE   | \Link.txt" |
    | echo | https://www.aptana.com/products/studio3/download | > " | Aptana Studio | \Link.txt" |
    +-------------------------------------------------------------------------------------------+
    Yup, I used Excel's good functions like fill, etc., and made this. Then I copied everything to notepad and used Find & Replace and replaced all the Tab characters to spaces and formatted the output. The final batch command was:
    echo https://netbeans.org/d...dows&lang=en&option=php > "NetBeans IDE\Link.txt"
    echo https://www.eclipse.org/d...developers/indigosr1 > "Eclipse IDE\Link.txt"
    echo https://www.aptana.com/products/studio3/download > "Aptana Studio\Link.txt"
    Finally, I copied all the files using the same batch command! 😀 It was a pretty awesome experience, isn't it??? 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorFeb 6, 2012

    That's some Crazy Engineering, Praveen 👍
    Are you sure? This action cannot be undone.
    Cancel
  • Dancer_Engineer

    MemberFeb 6, 2012

    That's work done awesomely! 👍
    Are you sure? This action cannot be undone.
    Cancel
  • KenJackson

    MemberFeb 6, 2012

    Yes, that's one of the more novel uses of a spreadsheet that I've seen.

    But I enjoy routinely whipping out scripts to do this sort of thing.
    On Windows I always install <a href="https://cygwin.com" target="_blank" rel="nofollow noopener noreferrer">Cygwin</a> so I have a bash shell.
    And on my preferred Linux platform, the bash shell is native.

    Here's a script that does approximately that, though I'm not sure of the URLs.

    #!/bin/bash
    DIR=("NetBeans IDE"
        "Eclipse IDE"
        "Aptana Studio"
        )
    FILE=("netbeans-7.1-ml-php-windows.exe"
          "eclipse-jee-indigo-SR1-win32.zip"
          "Aptana_Studio_3_Setup_3.0.8.exe"
        )
    URL=(
    "netbeans.org/downloads/start.html?platform=windows&lang=en&option=php"
    "www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr1"
    "www.aptana.com/products/studio3/download"
    )
     
    for n in $(seq 0 2); do
        dir="${DIR[$n]}"
        file="${FILE[$n]}"
        url="${URL[$n]}"
     
        cd /tmp                # or ~/Desktop or wherever
        mkdir -p "$dir"
        cd "$dir"
        wget -c "https://$url/$file"
    done
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberFeb 6, 2012

    KenJackson
    Yes, that's one of the more novel uses of a spreadsheet that I've seen.

    But I enjoy routinely whipping out scripts to do this sort of thing.
    On Windows I always install <a href="https://cygwin.com" target="_blank" rel="nofollow noopener noreferrer">Cygwin</a> so I have a bash shell.
    And on my preferred Linux platform, the bash shell is native.

    Here's a script that does approximately that, though I'm not sure of the URLs.

    #!/bin/bash
    DIR=("NetBeans IDE"
        "Eclipse IDE"
        "Aptana Studio"
        )
    FILE=("netbeans-7.1-ml-php-windows.exe"
          "eclipse-jee-indigo-SR1-win32.zip"
          "Aptana_Studio_3_Setup_3.0.8.exe"
        )
    URL=(
    "netbeans.org/downloads/start.html?platform=windows&lang=en&option=php"
    "www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigosr1"
    "www.aptana.com/products/studio3/download"
    )
     
    for n in $(seq 0 2); do
        dir="${DIR[$n]}"
        file="${FILE[$n]}"
        url="${URL[$n]}"
     
        cd /tmp                # or ~/Desktop or wherever
        mkdir -p "$dir"
        cd "$dir"
        wget -c "https://$url/$file"
    done
    Nice one, I thought of this, but I didn't wanna use programming here! 😛 I just used a Windows Batch file to keep all things right! 😀 Simple isn't it??? 😀
    Are you sure? This action cannot be undone.
    Cancel
  • eternalthinker

    MemberFeb 6, 2012

    Cool !

    And for future uses, we may code a simple loop which takes content and link as inputs in each iteration 😀
    (And create necessary files with the input)
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberFeb 7, 2012

    eternalthinker
    Cool !

    And for future uses, we may code a simple loop which takes content and link as inputs in each iteration 😀
    (And create necessary files with the input)
    Still wondering if loops work in Batch... I have been testing it for long!!! 😛
    Are you sure? This action cannot be undone.
    Cancel
  • Ankita Katdare

    AdministratorFeb 7, 2012

    😲 whoa! Never thought that could be done. Will try it some time.
    Great sharing CEan praveen. 👍
    Are you sure? This action cannot be undone.
    Cancel
  • Sahithi Pallavi

    MemberFeb 7, 2012

    Simply Awesome! I'll try it out 😀
    Praveen, you are really a Crazy Computer Science Engineer 👍
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberFeb 7, 2012

    Thankz Sada & AKD!!! 😁
    Are you sure? This action cannot be undone.
    Cancel
  • Reya

    MemberFeb 7, 2012

    Thanks for sharing it geeky 😀
    Are you sure? This action cannot be undone.
    Cancel
  • PraveenKumar Purushothaman

    MemberFeb 7, 2012

    Reya
    Thanks for sharing it geeky 😀
    Will share again if I become mad and do something great! 😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register