Advertisement

07.25.2008 at 04:04PM PDT, ID: 23597028
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

VB Utility App to Search Sub Folder to rename files with a specific extension

Asked by mydo76 in Visual Basic v1.0.5.x, VB Controls, VB Database Programming

Tags: , ,

I need to create a utility in VB 6.0 (for yesterday) that runs through all the subfolders of a specific folder eg C:\Backup. It needs to look for all files in each subdirectory with an ".ini" extention and rename them to ".live" (Keeping the same filname eg myfile.ini changes to myFile.live)
(In each Subfolder - Each ini file should have a corresponding filename.live so I need a check for this perhpas and an error raised)
 After all the ini files have been renamed to .live I need to rename all the files in the same subfolders with a .drp extention to .ini extention

I dont have vb on my pc so am coding blind. Could you please take a look at the code I've written and point out any amendments I need to make or a better way of doing things?. Any help would be appreciated. Thanks
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
Dim fso As New FileSystemObject
Dim f As Folder, sf As Folder, path As String
Dim file as File, iniFile as File, drpFile as File
Dim currFile as File
Dim inifiles() as string,  drpFiles as string
         
'Initialize path.
'path = Environ("windir")
path = Environ("P:\Programs\") 'THe root of the Subfolders to be searched is P:\Programs\
	
'Check the path exists
if not fso.FolderExists(path)
    MsgBox "Folder Does Not Exist" & path, vbOKOnly
end if 
'Get a reference to the Folder object.
   Set f = fso.GetFolder(path)
   If fld.SubFolders.Count > 0 Then
 
      'Iterate through subfolders.		  
       For Each sf In f.SubFolders
	  MsgBox "Sub Folder" & sf.Name
	 ' or Debug.Print sf.Name
 
          'Iterate through files in each subfolder 
	  'Do I need to do this to get access to files in a subfolder?
		
           ' First Change all .ini file to .live
           For each iniFile in sf 						        	
	   If Not iniFile.FileExists("*.ini") Then 		
             ' If No ini file exists in Subfolder Loop to next Folder
	     'loop to next sub directory
	  else
	    ' Get the file name 
	     Dim strIniFileName as string
	     strIniFileName = iniFile.name 
 
	  ' check this file extention
	  ' there might be more than one ini file 
	  ' How do i check this?
 
	 ' Use .GetExtensionName to check if its .ini perhaps
	   if iniFile.GetExtensionName = ".ini"			
                ' Or is this "ini" (no .)?
					
		dim nameNoExt as string
		dim newEXT as string
		Dim LiveFile  as string
		liveEXT  = ".live"				
					
	nameNoExt = Left(strIniFileName, InStr(strIniFileName, ".") - 1)
	LiveFile  = nameNoExt & liveEXT
 
	'rename ini to live				
	'Name strIniFileName as strIniFileName & ".live"
	Name strIniFileName as LiveFile	
					
  end if       
 
Next
   ' Do I need to Go back to the root folder from where I want to search   SubDirectories?	
 ' At this point I could check to ensure no ini files exist - they should all be .live files 
     ' If any exist - raise message
    ' Second Change all .drp file to .ini
    For each drpFile in sf 						  
    ' Check the email code for file in dir
		
	If Not drpFile.FileExists("*.drp") Then 		
         ' If No ini file exists in this Subfolder Loop to next Folder
	  'loop to next sub directory
	else
	 ' Get the file name 
	 Dim strDRPFileName as string
	 strDRPFileName = drpFile.name 
 
	  ' check this file extention
	  ' there might be more than one drp file 
	  '  How do i check this?
 
	' Use .GetExtensionName to check if its .ini perhaps?
	 if drpFile.GetExtensionName = ".drp"			
               ' Or is this just "drp"	(no .)?
					
	 dim nameNoExt1 as string
	 dim newEXT1 as string
	 Dim newINIFile  as string
	 drpEXT  = ".live"				
					
  nameNoExt1 = Left(strDRPFileName, InStr(strDRPFileName, ".") - 1)
  newINIFile = nameNoExt & liveEXT
 
	'rename ini to live				
        'Name strIniFileName as strIniFileName & ".live"
	  Name strDRPFileName as newINIFile	
					
     end if       
 Next
Next
 
 
End if ' End if - fld.SubFolders.Count > 0
 
Keywords: VB Utility App to Search Sub Folder to r…
 
Loading Advertisement...
 
[+][-]07.26.2008 at 03:08AM PDT, ID: 22094407

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.26.2008 at 03:08AM PDT, ID: 22094409

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Basic v1.0.5.x, VB Controls, VB Database Programming
Tags: Visual Basic, 6.0, Visual Basic 6.0
Sign Up Now!
Solution Provided By: zoofan
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.26.2008 at 05:35AM PDT, ID: 22094850

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.19.2008 at 12:43AM PDT, ID: 22257805

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.23.2008 at 08:21AM PDT, ID: 22297377

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628