Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other VB 6.0 Posts   Ask New Question  Ask New Question With Power Editor

Trying to right a VBScript that gets rid of files from a directory
Clive Valentine posted at Tuesday, November 03, 2009 11:15 AM

Hi,

I've tried to right a script that delete files of a certain type using the wildcard and _AFP_AFPINFO.

I've done some searching on the web and have come up empty as everything I found was for an extension or a file of a certain age.

Here's my test code, not entirely sure where I've gone wrong but I hope someone can put me in the right direction as it's driving me mad.

Thanks In advance

T1b

Dim objFSO, objFolder, objFiles, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFSO.GetFolder("C:\Test")
     Set colSubfolders = objFolder.Subfolders
  Set objFiles = objFolder.Files
   For Each objFile in objFiles
          If UCase(left(objFile.Name,6)) = "*_AFP_*" Then objFile.Delete, True
       Next
     Set objFiles = Nothing
   Set objFolder = Nothing
 Set objFSO = Nothing

 

Reply    Reply Using Power Editor
Lots of letters but still no clue
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0
Use the Percentage Symbol.
[)ia6l0 iii provided a rated reply to Clive Valentine on Tuesday, November 03, 2009 12:16 PM

The Condtion would never evaluate to true , because the substring returned by the left(objFile.Name,6) would never be equal to "*_AFP_*" (without quotes). I believe you did that because you needed the wildcard. 
 
I believe you need to use the percentage symbol when you do a search based on wildcard. Like:
"%AFP%"

You can put a breakpoint if you are using this in Visual Studio or do a Write call to figure out what the substring returns.
Reply    Reply Using Power Editor
  Rank Winnings Points
November 1 $217.00 560
October 1 $226.00 771

Or I think..
web mavin provided a rated reply to Clive Valentine on Tuesday, November 03, 2009 12:56 PM

you could also try "InStr" function that would search for the string in your filename.

Something like:-

iPositionIndex = Instr(objFile.Name, "_AFP_")

Reply    Reply Using Power Editor
  Rank Winnings Points
November 8 $22.00 56
October 7 $38.00 131