Solved

How to kill/delete files in a folder

Posted on 2009-04-08
6
559 Views
Last Modified: 2013-11-27
I am working in Access 2002 and I am trying to kill/delete files (if any) in my windows xp explorer folder.  I wrote the following constant to identify the path.  However when it gets to the if statement A_ImportDir_MIC actually equals the path so it drops into my if statement to kill the files even though there are no files in the folder Micros email attachments.  

How can I rewrite the script to make sure its looking for the files within the folder with the *.txt extensions and if there are none get out of the if statement?  Thank you.


<CODE>
Option Compare Database   'Use database order for string comparisons
Const A_ImportDir_MIC = "C:\Micros email attachments\"

'KILL THE FILES
      If A_ImportDir_MIC <> "" Then
        Kill "C:\Micros email attachments\*.txt"
      End If
0
Comment
Question by:Mahonek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24100888
you could try looping using dir

dim sFolder as string
dim sFile as string

    sFolder = "c:\myfolder\"
    sFile = Dir$(sFolder)
    Do While Len(sFile) > 0
         kill sFolder & sFile
         sFile= Dir$
    Loop

other way is to use the file system object
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 125 total points
ID: 24100911
   Dim fso As Object
    Dim sourceFolder As Object
    Dim f As Object
    Dim sFolder As String
   
   
    Set fso = CreateObject("Scripting.FileSystemObject")
   
    sFolder = "c:\myfolder\"
    Set sourceFolder = fso.GetFolder(sFolder)
    For Each f In sourceFolder.Files
        Kill sFolder & f.Name
    Next f
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24101015
If Dir(A_importDir_MIC & "*.txt") <> "" Then
  Kill A_importDir_MIC & "*.txt"
End If
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 65

Expert Comment

by:rockiroads
ID: 24101040
scripts I did deletes all files. Using the orignal dir method, you can add in *.txt to bring back text files only

a better way to use scripting is to create the file object then use the delete method instead of kill


0
 

Author Closing Comment

by:Mahonek
ID: 31568205
Great!  Thanks.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24101939
No worries, Sorry but I forgot to check for the txt instructions but that can be done by some simple string manipulation
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question