Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 22nd, 2003, 04:33 PM
km1234 km1234 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 10 km1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
File Count problem

hello,

i am using javascript to access files in a particular folder.I am doing this locally on my machine only. My script counts the number of files of a particular type and beginning with a particular character (eg 'r').

My script works fine. Now when I go in and try and change the contents of the folder, like add a file or rename a file, and then rerun my javascript it does not work correctly. i get some file names but not all.

i am posting part of my code here. Please look into this and let me know what I am doing wrong.

thanks,


************************

//this function is called by the main program

function countFiles(strPath,num,fp)
{
icount=0;

var objFSO = new ActiveXObject("Scripting.FileSystemObject"); //creation of filesystem object
var objFolder = objFSO.GetFolder(strPath);
var objFiles = objFolder.Files;
var filesCount = objFiles.Count; //filecount

var a1=new Array(filesCount);
var a2=new Array(filesCount);

i=0;
for(var objEnum = new Enumerator(objFiles); ! objEnum.atEnd(); objEnum.moveNext())
{
strFileName = objEnum.item().name;
strFileName1 = objEnum.item().type;
// WScript.Echo(strFileName);
a1[i]=strFileName;
a2[i]=strFileName1;
i++;
}

objEnum=null;
var a3=new Array();


//selection of files based on extension and starting char of name
for(i=0;i<filesCount;i++)
{
var p=a1[i].charAt(0);
if(p==cmpch & a2[i]=="PNG Image" )
{
icount++;
a3[i]=a1[i];
var a3_l=a3[i].length;
a3[i]=a3[i].substring(0,a3_l-4);
}

}

//after this I write out contents to output file.

}

Reply With Quote
  #2  
Old December 22nd, 2003, 04:43 PM
km1234 km1234 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 10 km1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
followup to code

just wanted to mention that in my code, i use two arrays to hold the file name and type of each file. (a1 & a2).

I use

strFileName = objEnum.item().name;
a1[i]=strFileName;

I define the arrays using
a1=new Array();

do i maybe need to define the array as a string array which can hold strings?

thanks and sorry for any confusion.

eagerly hoping for some input.

Reply With Quote
  #3  
Old December 22nd, 2003, 10:37 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
THis is a vb forum!Plz administrator move this message to other forum as "HTML, JavaScript & CSS"...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > File Count problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway