07 Feb 2012

Necessity is the Mother of Invention - Batch Job

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!!! 😀
7 years ago
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??? 😀
7 years ago
That's some Crazy Engineering, Praveen 👍
Dancer_Engineer

Dancer_Engineer

Branch Unspecified
7 years ago
That's work done awesomely! 👍
KenJackson

KenJackson

Branch Unspecified
7 years ago
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 cygwin 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
7 years ago
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 cygwin 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??? 😀
eternalthinker

eternalthinker

Branch Unspecified
7 years ago
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)
7 years ago
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!!! 😛
Ankita Katdare

Ankita Katdare

Computer Science
7 years ago
😲 whoa! Never thought that could be done. Will try it some time.
Great sharing CEan praveen. 👍
Sahithi Pallavi

Sahithi Pallavi

Computer Science
7 years ago
Simply Awesome! I'll try it out 😀
Praveen, you are really a Crazy Computer Science Engineer 👍
7 years ago
Thankz Sada & AKD!!! 😁
Reya

Reya

Branch Unspecified
7 years ago
Thanks for sharing it geeky 😀
7 years ago
Reya
Thanks for sharing it geeky 😀
Will share again if I become mad and do something great! 😀

Share this content on your social channels -

Only logged in users can reply.