September 30, 2007

27

VBScript to Replace Underscores in Filename with Spaces for All Files in a Folder

Sometimes I wanted to remove underscores in file name and replace it with space. For example I would like to see the filename as 'Sharifah Aini - Suasana Hari Raya.mp3' instead of 'Sharifah_Aini_-_Suasana_Hari_Raya.mp3'. I often have this kind of files when I download mp3s on the internet. I know this maybe so simple because you can just select the file in Windows Explorer, Press F2 and manually rename the file. But for a collections of files in a folder, this may be a boring repetitive task that I'll hate to do.

So, as a damn lazy coder , I've wrote a short Visual Basic Script to automatically do the task with only one simple command. I think this VBScript maybe useful for you too. So, I would like to share my VBScript to replace underscores in filename with spaces for all files within a folder. Here's the script...


'========================================================
' VBScript to replace underscore in file name with space
' for each files in a folder
' Written by ApOgEE of http://coderstalk.blogspot.com
'========================================================
Dim sName
Dim fso
Dim fol

' create the filesystem object
Set fso = WScript.CreateObject("Scripting.FileSystemObject")

' get current folder
Set fol = fso.GetFolder(".")

' go thru each files in the folder
For Each fil In fol.Files
' check if the file name contains underscore
If InStr(1, fil.Name, "_") <> 0 Then
' replace underscore with space
sName = Replace(fil.Name, "_", " ")
' rename the file
fil.Name = sName
End If
Next

' echo the job is completed
WScript.Echo "Completed!"

To use the script, you just need to copy this scripts to a text file and then name the textfile with 'rmus.vbs' or any other name you like with '.vbs' extension which is for vbscript.

There is lots of ways to use the script. One of them is, copy the .vbs file to the folder you want the task to be done and then double click the .vbs file in that folder. When the script is done, it will prompt you with a message box which says 'Completed!'. I'll post the other ways to run this kind of scripts later. Feel free to bookmark or subscribe this blog to automatically get updates on this blog.

If you like this code, feel free to use it and if you like to spread it on the net, please gimme a link to this page. I would love to hear your comments too!

Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy




September 23, 2007

0

Visual Basic Programming: How to check element exists in Collection

One of the missing function code that made by the VB Class Builder while making a Collection Class is CheckExists function to check whether the key associated to an object in the collection is already exists or not.

Collections in Visual Basic

In general, a collection is an object used for grouping and managing related objects. Check out Microsoft article about Collections in Visual Basic

Creating Collection Class using VB Class Builder

The simplest way to create collection class is by using the VB Class Builder. Here's the simple step:
  • Right click on the Project Explorer area
  • Select Add > Class Module
  • Select VB Class Builder, and click Open
  • Select File > New > Collection and Set your class to be grouped it the Collection Class, Set The collection Name and click OK
  • Update Project and Close the Builder

Notice, you will have one new class based on the name you set on the Builder. Open the code window for the New Collection Class and you will notice there is no CheckExists function to check whether the key associated to an object it the collection is already exists or not.

Here is my function code to check if an object exists in a collection object
Public Function CheckExists(vntIndexKey As Variant) As Boolean
On Error Resume Next
Dim cObj As Object

' just get the object
Set cObj = mCol(vntIndexKey)

' here's the key! Trap the Error Code
' when the error code is 5 then the Object is Not Exists
CheckExists = (Err <> 5)

' just to clear the error
If Err <> 0 Then Call Err.Clear
Set cObj = Nothing
End Function

You can simply copy this code and paste it in the Collection class and now you have the CheckExists function in your collection Class. Good Luck!

Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

September 22, 2007

0

Some Useful Linux Commands

I can't declare myself as linux user since I didn't use linux as my main operating system on my computers. But I do use linux when needed. Since then, I always forget the commands when I didn't touch linux for years. Now I'm working on with linux again and I have to recall all the commands back again. So, to make my future search for useful commands more quickly, I compiled my linux commands here.

ls - list file or directory
Example Usage:

root@OpenWrt:/# ls
bin dev etc jffs lib mnt proc rom sbin tmp usr var www
root@OpenWrt:/#

cd - change directory
Example usage:
root@OpenWrt:~# cd /jffs
root@OpenWrt:/jffs#

cat - view text in a file
Example usage:
root@OpenWrt:/etc# cat banner
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
WHITE RUSSIAN (0.9) -------------------------------
* 2 oz Vodka Mix the Vodka and Kahlua together
* 1 oz Kahlua over ice, then float the cream or
* 1/2oz cream milk on the top.
---------------------------------------------------
root@OpenWrt:/etc#

echo - echo a strings
root@OpenWrt:/# echo 'this is the first line
> and second line
> the third
> and then fourth' > mytextfile
root@OpenWrt:/# cat mytextfile
this is the first line
and second line
the third
and then fourth
root@OpenWrt:/#

insmod - install a kernel module
root@OpenWrt:/# insmod mmc
Using /lib/modules/2.4.30/mmc.o
root@OpenWrt:/#

lsmod - list of installed kernel module
root@OpenWrt:/# lsmod
Module Size Used by Tainted: P
mmc 26604 0 (unused)
wlcompat 15744 0 (unused)
ip_nat_irc 2336 0 (unused)
ip_conntrack_irc 3128 1
ip_nat_tftp 1824 0 (unused)
ip_conntrack_tftp 1728 1
ip_nat_ftp 2960 0 (unused)
ip_conntrack_ftp 4320 1
wl 423640 0 (unused)
switch-robo 4460 0 (unused)
switch-core 4912 0 [switch-robo]
diag 19808 0 (unused)
root@OpenWrt:/#

rmmod - uninstall a kernel module
root@OpenWrt:/# rmmod mmc
root@OpenWrt:/#

Umm... maybe enough for today coz I have things to do now. I'll update this post later...

Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy




September 20, 2007

4

How to get Windows XP command prompt output to Notepad

Sometimes we need to copy output from a command prompt and paste it into a Windows program such as Notepad. Usually, you’ll try to use the Mark and Copy commands on the command prompt’s Edit menu. I recently found an article from Tech Republic about Copy and paste from Windows XP Pro’s command prompt straight to the Clipboard where Greg Shultz is introducing a command line tool called Clip.exe. But I have my own way to get information from a command prompt and onto your notepad without using the Clip.exe.

It is so simple. Lets say, you want to get the output from ipconfig command, then just add a '>' and type the name of text file you want like 'ipconf.txt'. On the command prompt it will look like this:


Then, you can view your output on notepad by simply type 'notepad ipconf.txt' and press enter like this:


That's all. Good Luck and have fun! Anyway, you may want to view Greg Shultz's tips on how to Copy and paste from Windows XP Pro’s command prompt straight to the Clipboard using Clip.exe

Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

September 8, 2007

1

The Science of Computers

Apart from being a Software Engineer for a Wireless Broadband company in Malaysia, a part time graphic designer who has that passion of art and designs, a husband of a beautiful wife and a part time blogger, I’m also an undergraduate student of SPACE (School of Professional and Continuing Education) under UTM (University Technology Malaysia) pursuing my Degree in Computer Science.

You may wonder how busy my daily routine is. But that’s what I’m currently doing. And that’s also why sometimes I have to leave this blog untouched without an updates. However, I’m trying to keep this blog alive and now I’m planning to share my understanding in subjects taken through my degree courses which I think may be helpful for those who are interested about Computer Science on this Coder’s Talk Blog.

This semester, I’m taking three subjects which were Accounting Information System (SCM4253), Office Automation (SCM4213) and Strategic Management and Information System (SCM3153). So this time, I will blog about this three subjects until the end of semester. So stay tune with this blog and we will soon discover and understand these three subjects in the adventure to discover the Science of Computer.

Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy