473,503 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hi..Help Needed for deletion using VB

19 New Member
Hi

I need one small help in VB
I have written a macro which produces some output and stores them in the form of an excel files (about 10 files are generated) in a particular directory in C:\.
The requirement is that each time when the macro runs, it shall first delete the existing files in that directory and rewrite new files.So the problem comes in deletion of existing file...The generation of file is taken care by macro.
If u can provide me the code for deletion, I will b thankful

Regards
Sanket
Nov 16 '06 #1
7 1224
albertw
267 Contributor
Hi

I need one small help in VB
I have written a macro which produces some output and stores them in the form of an excel files (about 10 files are generated) in a particular directory in C:\.
The requirement is that each time when the macro runs, it shall first delete the existing files in that directory and rewrite new files.So the problem comes in deletion of existing file...The generation of file is taken care by macro.
If u can provide me the code for deletion, I will b thankful

Regards
Sanket
hi

use the statement KILL path & filename
Nov 16 '06 #2
Sanket80
19 New Member
hi

use the statement KILL path & filename
Hi,

Thanks for the reply...I tried that before using the following function code

Function delfiles1()

Dim strFldr As String
Dim strFile As String

strFldr = "C:\Results\Reports1" ' select the directory
strFile = Dir(strFldr & "\*.*") ' get list of files in folder

Kill strFldr & "\" & strFile

End Function

But the problem is that it is not deleting the files using above code and hence when the macro runs for the second time ....it shows up the message while saving the file .."that the file already exists".
Can you please review and let me know in case there is anything wrong with the code. Please note that the directory contains several files and I need to delete all of them together.

Regards
Sanket
Nov 16 '06 #3
Sanket80
19 New Member
Please note that the code deletes in case there is only one file in the directory but does not deletes in case there are multiple files.
Nov 16 '06 #4
albertw
267 Contributor
Please note that the code deletes in case there is only one file in the directory but does not deletes in case there are multiple files.
hi

strFldr = "C:\Results\Reports1" ' select the directory
strFile = Dir(strFldr & "\*.*") ' get list of files in folder

Kill strFldr & "\" & strFile

why not:

strFiles="c:\result\reports1\*.*"
Kill strFiles
Nov 17 '06 #5
albertw
267 Contributor
or even

Private Function delfiles()
On Error Goto Fail
Kill "c:\result\reports1\*.*"
Fail:
Err.Clear
End Function

the errortrap just in case there is no file in your folder.
Nov 17 '06 #6
schandraram
5 New Member
Please note that the code deletes in case there is only one file in the directory but does not deletes in case there are multiple files.
Just as a matter of explanation...

the Dir() function returns the name (not the full path) of the _first_ file found for the specified string. So Dir("*.*") will return only one name and so the Kill statement only deletes that file.
Nov 17 '06 #7
Sanket80
19 New Member
Hi,

Thanks to both of you.
The code worked perfectly

Regards
Sanket
Nov 17 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1860
by: Raghuraman | last post by:
Hai 1. Is it possiable to delete a record from the parent table.It is even ok to me , if it leads to the deletion of all the child tables . 2.I 've come across a situiation where the name...
11
2242
by: William Payne | last post by:
Ok, in my program I have a std::list<Document*>, where Document is one of my own classes. I need to go through this list and check each item if it's ready for deletion. If it's not, skip to...
6
2859
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
6
2261
by: iam247 | last post by:
Hi I am a relative beginner with ASP and weak on syntax for sql statements. Basically I modify something which works. I have tblGroupContact with two fields both long integer - ContactID &...
4
9002
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
4
3570
by: MikeY | last post by:
Hi everyone, I have posted earlier this week, but I'm still scratching my head trying to figure out how to change/modify my data back to my db. Using C# Windows forms. I am trying to learn how...
0
2163
by: ferdz3001 | last post by:
Hi, I have read some of the forums regarding deletion of log files. Just to get more information before I perform the deletion of log files. These are the steps I got: 1. db2 get db cfg <DBSID>...
6
2848
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.