Programming, Solution

VBScript: Folder Monitoring

Hi,

There’s a scenario where there’s an active folder where files are coming in and out, so the key objective of the program is to ensure that the folder always stay empty. Any files that stay more that 30 minutes is consider an alert and it needs to be taken care of and the alert will be sent through email.

So below are the code and it is triggered every 15 minutes using the Task Scheduler :

Note: The Outlook application has to be running, otherwise it will go to the outbox folder and the mail will be sent after the outlook application is running


age_threshold = 30 'in minutes

folderPath = "path"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.getFolder(folderPath )

file_found = 0

Set shell = wscript.CreateObject("Shell.Application")

For Each fl in fldr.Files
age = DateDiff("n", fl .DateCreated, Now)
If age > age_threshold Then
file_found = file_found+1
End If
Next
if file_found > 0 then
sendAlert(file_found)
WScript.Quit()
else
WScript.Quit()
end if

sub sendAlert(no)
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
objMail.Display 'To display message
objMail.To = "xyz@xyz.com"
objMail.Subject = "Alert: Folder XYZ"
objMail.Body = "Please check the XYZ folder - "&folderPath
objMail.Send
Set objMail = Nothing
Set objOutlook = Nothing
end sub

-Farrah K.

Advertisements
Programming, Solution

VBScript: Content Search

Hi,

I used to write codes in Visual Basics, it was long time ago. Never thought that I will use it again until recently with my current job which using VBScript. For my understanding is that VB is more to application while VBS is more to script language that runs command, more like a batch file. In another word, VBS is the light version of VB. (in a sense haha)

For the first time, I was given a sample before I write it then after writing it I quite surprise VBS can do a lot with the files which I have been doing it manually years ago when I was in my uni. Some of the things that I wish I knew it back then so I could just write it and let the task scheduler do the works haha.

OK, so one of the tasks that have given to me was to search for numbers among 100-500++ files. So what I did was I wrote the code below which I called it “smart lookup” hehe… Below are just the small chunk of it but definitely a keeper:

num= InputBox("Please enter the number","Look for")
Set result Set fldr = fso.GetFolder(folderpath)
Set fls = fldr.Files
Set d=CreateObject("Scripting.Dictionary")
n=1

For Each fl In fls
Set r= fl.OpenAsTextStream(1)
content = r.ReadAll
if instr(1,content,num) then
d.Add "a" & n, fl.name
n=n+1
end if
r.close


Next
allRslt=d.Items
counter=d.Count

set w= result.CreateTextFile("result.txt") 'put all the result into this file, just in case it appears in multiple files
if counter>0 then
For i=0 to counter-1
w.WriteLine allRslt(i)
Next
end if
w.close

So this is just one of it that I’ve done and it’s quite handy.. Next post I’ll share you another task using VBScript

-Farrah K.

Programming, Solution

GitHub Introduction

Git is an open-source version control system.

Hub is where developers can store and share their projects.

GitHub is ideal for programmers may have you believing that they are the only ones who will find it useful. Although it’s a lot less common, GitHub can actually be used for any types of files – so if you have a team that is constantly making changes to a word document, you can actually use GitHub as your version control system.

To setup a GitHub account is easy however as for me the managing part at first is a bit complicated but I figure out how and finds it easy.

After you opened a GitHub account, it is recommended for you to install GitHub on your desktop (Windows). Just go to Here

Once it is installed, there are 2 applications: GitHub and Git Shell.

In order to use the Git Shell, it is best if you know the basic commands of Linux like rm, mkdir, mv, ls, etc. But no worry there are always plenty of sites that you can refer to. I usually refer Here

As for GitHub, it is easy to use and any changes made to the files or folder will be updated and you will have to commit and then sync with your GitHub online. Furthermore, if you write codes using Visual Studio you can also link it with your GitHub.

What you do is:

  1. Open up Visual Studio, I’m using Visual Studio 2015.
  2. On the menu tab, go to Tools > Extensions and Updates…
  3. On the side menu, go to Online and search for GitHub.
  4. Look for GitHub Extension for Visual Studio, download and install.
  5. Restart the application.
  6. So after you create a new project, on the menu bar go to File > Add Source Control.
  7. Select Git.
  8. If you want to use it for the rest of the new project then check the check box otherwise just let it be unchecked.
  9. Go to the Team Explorer tab on the right side of the application:
    Capture
  10. Go to Settings, and check if everything is correct
  11. Click the icon that look like a plug  Capture
  12. Then click connect under GitHub and log in with your username and password
  13. Under the GitHub, you may or may not want to clone from your GitHub, if you do then just copy the link from your GitHub: HTTPS clone URL. Otherwise, just create a new Repository.
  14. So whenever you are ready to update your GitHub, you will need to click on Changes > Enter a message and click Commit
  15. After commit is done then you have to sync by going to the Sync
  16. Then the GitHub will be updated.

You may find it a bit hard to follow for few days but you’ll get there. If you need help just write a comment and I try my best to help you.


Nothing much yet on my GitHub as I just started to use it but feel free to visit 😀

My GitHub: Here

-Farrah K.

Programming

Python Programming Language (Basic)

I always listen to people that they have learn to code using Python and it makes me wonders for all this time so today I’ll be showing you how to code using Python, just basic nothing advance. If you’re a hardcore programmers, Python is easy and simple in fact it is one of the easier ones to learn. Python has different version such as IronPython, IPython, CPython, PyPy, Jython, Canopy and more. In this post, I’ll be using the CPython. Below is the list that I’ve installed:

  • Visual Studio Ultimate 2013
  • Python Tools for Visual Studio
  • Python 3.4 interpreter

Let’s start.

  • Open up the Microsoft Visual Studio.
  • Click New Project, select Python and select Python Application as shown below.

2-8

  • Name, HelloWorld and Click OK.
  • And you’ll see blank page as shown below:

2-8 And there you can write the code, example: print('Hello World') name = input("What is your name? ") print("\nYour name is: " + name) print(name.lower()) print(name.upper()) print(name.swapcase()) To run the program, Click on the Start on the menu bar. Untitled Output: Capture


Another example on numbers: no1 = 5 no2 = 2 add = no1 + no2 #addition sub = no1 - no2 #subtration mul = no1 * no2 #multiplication div = no1 / no2 #division exp = no1 ** no2 #exponent mod = no1 % no2 #modulo print("Numbers: %d , %d" % (no1, no2)) print("Addition: %d" % no1 + " + %d" % no2 + "= %d" % add) print("Subtration: %d" % no1 + " - %d" % no2 + "= %d" % sub) print("Multiplication: %d" % no1 + " * %d" % no2 + "= %d" % mul) print("Division: %d" % no1 + " / %d" % no2 + "= %d" % div) print("Exponent: %d" % no1 + " ** %d" % no2 + "= %d" % exp) print("Modulo: %d" % no1 + " %% %d" % no2 + "= %d" % mod) Have you notice that Python has a different ways of displaying the numbers. It uses the placeholder just like C/C++. Output: Capture


That’s it for basic programming using Python. And… you’ll probably ask why should we learn Python when there are tons of other languages that you could use and Python seems like it is going to be faded away anytime soon (that’s what I thought at the beginning). Well it’s not and it is widely use, it is extremely popular in data science, bioinformatics.  And… do you know that? (Honestly speaking I just know this). Google, Yahoo!, Instagram, Dropbox and YouTube use it for their site too! (I find this fascinating, don’t you?)


-Farrah K.

Programming

First C# Application

As a programmer we have seen this ‘Hello World’ for so many times especially when we want to create a program with a new programming languages. So today I’ll be showing you the steps on creating a Hello World application using C#.

I believe there are more than one developer tool to write a C# application, as for this blog I’ll be using the Microsoft Visual Studio Ultimate 2012.

OK, here we go…

  • Open up the Microsoft Visual Studio.
  • Click New Project, select Visual C# and select Console Application as shown below.

Untitled

  • Name, HelloWorld and Click OK.
  • And you’ll see something like this:

Untitled


  • Tips: it is recommended to display the line numbers so it is easier for you to refer to.
  • To enable the Line numbers all you have to is:
    • Go to Tools > Options…
    • Expand the Text Editor > All Languages > General.
    • Select Line numbers under Display.

Untitled


Now, let’s write some code

  • Under the main method, write the code like this:

Console.WriteLine("Hello World");
Console.ReadLine();

  • To run the program, Click on the Start on the menu bar.

Untitled

  • And you’ll see:

Untitled


That’s it! You just created your Hello World using C#.

-Farrah K.