Not getting at subfolder files

My script is not getting at files in subfolder

Page 1 of 1

2 Replies - 2795 Views - Last Post: 22 October 2008 - 03:38 AM Rate Topic: -----

#1 dmcollette664   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-September 08

Not getting at subfolder files

Post icon  Posted 21 October 2008 - 10:46 AM

I am having trouble getting files in my subfolder to display. Was at one point getting files in main folder to display, but have made so many changes that the code is not running (expecting a statement at end of code). All help is appreciated.

What the code is supposed to do is:
'This script will check for number of parameters entered, existance
' of the drive entered, whether the drive is ready, if folders
' exist, if there are subfolders and should display the subfolders
' for the user. It will then prompt the user for the folder
' name, check for the existance of the folder, existance of files
' and if there are files, will list those.


Option Explicit
Dim fso, folders, myfiles, count, mess, myfolder, mypath					'sets variables
Dim ObjWshArgs, myfile, mydrives, mydrive, usrinput,mysubfolders
Dim drive,yourfolder,yourfiles,yourpath,yoursubfolder, file, x
Dim myarray(), arrcount
Set ObjWshArgs = WScript.Arguments												'gets an object		
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")					'gets an object

'use the WshArguments object's count property to verify that 2 arguments
'(parameters) were received. 

If ObjWshArgs.Count <= 1 Or ObjWshArgs.Count >= 3 Then
  
   MsgBox "I require exactly (2) two Parameters"								'error message to user when correct parameters not recieved
   															
   
End If

mydrive = ObjWshArgs.Item(0)													'sets a few variables
myfolder = ObjWshArgs.Item(1)
mypath = mydrive & ":" & "\" & myfolder
yourpath = mydrive & ":" & "\" & myfolder  & "\" & usrinput


If fso.DriveExists(mydrive) Then												'tests if drive exists
	MsgBox "Drive " & mydrive & " is found."
Else
	MsgBox "Drive " & mydrive & " is not a valid drive."						'error message if drive not found
	WScript.Quit
End If
 
set drive = fso.GetDrive(mydrive)
If drive.isready Then														'tests if drive is ready
	MsgBox "Drive is ready."
Else
	MsgBox "Drive " & mydrive & " is not ready."							'error message if drive not ready
	WScript.Quit
End If
	 
  
If fso.FolderExists(mypath) Then
   Set myfolder = fso.GetFolder(mypath)
   Set mysubfolders = myfolder.SubFolders
	   If mysubfolders.Count = 0 Then
		   MsgBox "No Subfolders to display."
		   WScript.Quit
Else
   count = 0
	  For Each myfolder In mysubfolders
	  mess = mess & myfolder.name & VbCrLf
	  count = count + 1
			   
	  Next 
			  
	  usrinput = InputBox( mess,"Please choose a subfolder from the list.")
		  
	  End If
  Else 
		MsgBox "Folder " & usrinput & " not found."
End If

   
   
   If fso.FolderExists(yourpath) Then
	   Set yourfolder = fso.GetFolder(yourpath)
	   'Set yoursubfolder = yourfolder.SubFolders
   	   Set yourfiles = yourfolder.Files
	 	
		'count = count + 1
	   		If yourfiles.count=0 Then
		 	MsgBox "Your folder " & usrinput & " does not contain any files.",,"Oh, My!"
		 	WScript.Quit
	  
	Else
			For Each file in yourfiles 
			'count = 0
		   'If yourfiles.count>0 Then
			'ReDim myarray(yourfiles.Count)
			'For each x in myarray
			'count = count + 1
		 	mess = mess & file.name & VbCrLf
	 			  
	 Next
			  'For x.count <=20
			MsgBox mess,,"Here are your files. "
			End If
		
	 Else
	 
	   MsgBox "Your folder " & yourfolder & " has not been found."
	   WScript.Quit
		End If
	End If



Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Not getting at subfolder files

#2 thava   User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: Not getting at subfolder files

Posted 21 October 2008 - 04:12 PM

i think
better you use a do loop
if the user enter a string add with mypath and check the folder or file exists
if exists check if its a file or folder
if folder and it contains sub folders
again continue the do loop

get the user inpur same thing above

just like an recursive algorithm
Was This Post Helpful? 0
  • +
  • -

#3 dmcollette664   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-September 08

Re: Not getting at subfolder files

Posted 22 October 2008 - 03:38 AM

[quote name='thava' date='21 Oct, 2008 - 04:12 PM' post='442698']
i think
better you use a do loop
if the user enter a string add with mypath and check the folder or file exists
if exists check if its a file or folder
if folder and it contains sub folders
again continue the do loop

get the user inpur same thing above

just like an recursive algorithm



Thanks thava, I will try that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1