Friday, 8 February 2013

solution for How to rename files located in folder....

' This particular Code will fetch all the files in the given folder path
Function ShowFolderList(folderspec)
 Dim fso, f, f1, fc, s
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.GetFolder(folderspec)
 Set fc = f.Files
 fileCount=0
 For Each f1 in fc

 s = f1.name

' t1=split(s,"_")
 If instr(1,s,"_Date")>1 Then

  newName=  mid(s,1,Instr(1,s,"_Date")-1)
 
  f1.name=newName&".xls"
   Else
     newName = f1.name
 End If

 fileNames=fileNames&vbNewLine&s&"         "&newName&".xls"
 fileCount=fileCount+1
 Next
' fileNames=fileNames&vbNewLine&"------------------------------------------------"&vbNewLine&"Total Files in the folder: '"&folderspec&"' are : "&fileCount

 Set fOutput=fso.OpenTextFile("C:\ICAM\FileNames.txt",2,True)
 fOutput.Write "Total Files in the folder: '"&folderspec&"' are : "&fileCount&vbNewLine
 fOutput.Write "------------------FILE NAMES ARE------------------------------"
 fOutput.Write "-------Old File Name                 New File Name----------------------------"
 fOutput.Write fileNames
 Set fOutput=Nothing
 Set fso=Nothing
 MsgBox "File Names were successfully copied into file name: 'D:\FileNames.txt'"
End Function

folderspec=InputBox("Enter Folder Path")'"C:\Documents and Settings\719826\Local Settings\Temp"
Call ShowFolderList (folderspec)
'
't1 = "A3a-003_Date_6_2_2013_13_13.xls"
'msgbox mid(t1,1,Instr(1,t1,"_Date")-1)

Friday, 7 December 2012

VBScript Interview Qustions...

1.Read any 4 numbers and displays the reverse order?

Dim num,rnum,revdig
Dim numArray(10)


num = inputbox("enter the number")
rnum =0
revdig =0
 
jx= len(num)
for ix=0 to jx
 revdig = num mod 10
 rnum = (rnum*10)+revdig
 num = num /10
 itx = jx-ix
 if itx =1 then
  exit for
 end if
 num =left(num,itx)

Next
msgbox rnum



2. write a vbscript  to create  textfile and delete file?

dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("D:\123.txt") Then
        fso.DeleteFile"123.txt"
     Wscript.Echo("File deleted")
    Wscript.Echo("New File is creating")
     set file = fso.CreateTextFile("D:\123.txt", True)
    file.Writeline("Hello world")
End If