Vbs Count Files With Extension
I'm in the process of learning VBScript and I had a question. My first project is to create a script that will sort files based on extension from a temporary download folder and then place them into their proper homes. Set fso = CreateObject('Scripting.FileSystemObject') set directory = fso.GetFolder('.' Jun 24, 2006. Sometimes you might require to get a list of all the files in a folder, I was thinking how it can be implemented, the solution is to used the WSH. Echo 'No Folder parameter was passed' Wscript. But i must filter the files i want listed in the.txt file by the extension of the files. Could someone help me?
I am trying to find a specific file on computer and delete it. Your approach is much too complicated. Yes, I tried it multiple times and the results were the same within a 10% deviation. @Vojtech; it will help if you use the query 'SELECT * FROM CIM_DataFile WHERE Drive='c:' AND FileName=' & filename & '' if you first test it. It will only search your C: drive.
If that works, you can create a more generic query over multiple drives. Filename can only be the real filename without extension, but I think you can figure out how to implement the extension in the query. To Test: create a testfile.txt anywhere on your C: and Call the function as: call find_files('testfile') – Jan 31 '12 at 16:33.
The following script will do the job: __________________________ __________ __________ Main Sub Main redim extensions(10) redim number(10) Dim Path Select Case WScript.Arguments.Count Case 0: Path = '*.*' ' list current directory Case 1: Path = WScript.Arguments(0) Case Else: WScript.Echo 'Invalid number of arguments.' : Exit Sub End Select ListDir Path, extensions, number If extensions(0)=' then WScript.Echo 'No files found.' Exit Sub End If Dim ext For i=0 to ubound(extensions) if extensions(i)=' then exit for WScript.Echo 'Extension ' & extensions(i) & ' occurs ' & number(i) & ' time(s)' Next End Sub Public sub ListDir (ByVal Path, byref extensions, byref number) Dim fso: Set fso = CreateObject('Scripting.Fi leSystemOb ject') If Path = ' then Path = '*.*' Dim Parent, Filter if fso. Monarch Pro 11 Keygen Software on this page. FolderExists(Path) then ' Path is a directory Parent = Path Filter = '*' Else Parent = fso.GetParentFolderName(Pa th) If Parent = ' Then If Right(Path,1) = ':' Then Parent = Path: Else Parent = '. Wii Console Skin Template Dji on this page. ' Filter = fso.GetFileName(Path) If Filter = ' Then Filter = '*' End If Dim Folder: Set Folder = fso.GetFolder(Parent) Dim Files: Set Files = Folder.Files Dim File For Each File In Files dim ext dim indx indx=InStrRev(File.Name,'. ') if indx0 then ext=Mid(File.Name, indx) for i=0 to ubound(extensions) If i >ubound(extensions) - 2 Then ReDim Preserve extensions(i*2) ReDim Preserve number(i*2) end if if extensions(i)=' then extensions(i)=ext number(i)=1 exit for end if if extensions(i)=ext then number(i)=number(i)+1 exit for end if next end if Next End sub __________________________ __________ __________ You can pass the target directory as a command line argument. ______________ Nayer Naguib.