I am trying to write some code that when I exit my application kills all of
the text files in a certain folder. It is possible that some of those files
are locked because someone else is using them, in which case they will have
the first two letters of their name replaced with ~$. How can I write a
routine that will delete all the normal *.txt files, but not attempt to
delete the ~$ ones, which brings up an error message and prevents the
program from closing. I thought this would be easy, but I have not managed
to do it after quite a while trying.
dixie 14 2597
"Dixie" <di***@dogmail.com> wrote in
news:43********@duster.adelaide.on.net: I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
Scan the directory in question using the dir() function.
Then code an if block that deletes the offending files.
Untested code:
x = dir$("C:\directory to clean")
do while len(x) >0
if left(x,2) <> "~$" then
kill x
endif
x = dir$
loop
--
Bob Quintal
PA is y I've altered my email address.
I've got something like that working OK, except, when there is a ~$ style
file, it is locked and I always get an error, even if I am just trying to
jump over it and delete any other file that does not start with that
character combination.
dixie
"Bob Quintal" <rq******@sympatico.ca> wrote in message
news:Xn**********************@207.35.177.135... "Dixie" <di***@dogmail.com> wrote in news:43********@duster.adelaide.on.net:
I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie Scan the directory in question using the dir() function. Then code an if block that deletes the offending files.
Untested code:
x = dir$("C:\directory to clean") do while len(x) >0 if left(x,2) <> "~$" then kill x endif x = dir$ loop
-- Bob Quintal
PA is y I've altered my email address.
How about something like this:
On error resume next
x = dir$("C:\directory to clean")
do while x<>""
kill x
x = dir$
loop
Of course that assumes that the directory contains nothing but the .txt
files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message
news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all
of the text files in a certain folder. It is possible that some of those
files are locked because someone else is using them, in which case they will
have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not
managed to do it after quite a while trying.
dixie
I don't know what it is I'm doing wrong, but here is the exact code I am
using
Function KillMergeFiles()
On Error Resume Next
Dim x As String
x = Dir$("T:\Test")
Do While x <> ""
Kill x
x = Dir$
Loop
End Function
I have that code in a module and I am running it temporarily from a button
with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are
currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message
news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
I have turned my attack to a different method
Sub DeleteFilesThatIDontWant()
Dim fso
Dim sfol As String
sfol = "T:\Test"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid
Source"
Else
fso.deleteFile (sfol & "\*.txt")
End If
End Sub
That will delete all the txt files, but when it comes across a ~$xxxxx.txt
file which is in use, it fails to delete ANY of the files. My problem is
how do I make it ignore that file and delete the others?
dixie
"Dixie" <di***@dogmail.com> wrote in message
news:43******@duster.adelaide.on.net... I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles() On Error Resume Next Dim x As String x = Dir$("T:\Test") Do While x <> "" Kill x x = Dir$ Loop End Function
I have that code in a module and I am running it temporarily from a button with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
Dixie wrote: I have turned my attack to a different method
Sub DeleteFilesThatIDontWant()
Dim fso
Dim sfol As String
sfol = "T:\Test"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
Else
fso.deleteFile (sfol & "\*.txt")
End If
End Sub
That will delete all the txt files, but when it comes across a ~$xxxxx.txt file which is in use, it fails to delete ANY of the files. My problem is how do I make it ignore that file and delete the others?
Can you delete the files from Explorer?
Try this instead:
x = Dir$("T:\Test\*.txt")
"Dixie" <di***@dogmail.com> wrote in message
news:43******@duster.adelaide.on.net... I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles()
On Error Resume Next
Dim x As String
x = Dir$("T:\Test")
Do While x <> ""
Kill x
x = Dir$
Loop
End Function
I have that code in a module and I am running it temporarily from a button with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills
all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write
a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
Try: Kill "T:\Test\*.txt"
That will delete all txt files in the T:\Test folder in one line of code.
If that doesn't work then they must be openned and locked by something.
Ian.
"Dixie" <di***@dogmail.com> wrote in message
news:43******@duster.adelaide.on.net... I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles()
On Error Resume Next
Dim x As String
x = Dir$("T:\Test")
Do While x <> ""
Kill x
x = Dir$
Loop
End Function
I have that code in a module and I am running it temporarily from a button with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
So trap the error generated and resume next or jump to an appropriately
positioned label.
There are times where you can't do anything other than use the error
condition as a flag for program branching.
--
Terry Kreft
"Dixie" <di***@dogmail.com> wrote in message
news:43********@duster.adelaide.on.net... I've got something like that working OK, except, when there is a ~$ style file, it is locked and I always get an error, even if I am just trying to jump over it and delete any other file that does not start with that character combination.
dixie
"Bob Quintal" <rq******@sympatico.ca> wrote in message news:Xn**********************@207.35.177.135... "Dixie" <di***@dogmail.com> wrote in news:43********@duster.adelaide.on.net:
I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie Scan the directory in question using the dir() function. Then code an if block that deletes the offending files.
Untested code:
x = dir$("C:\directory to clean") do while len(x) >0 if left(x,2) <> "~$" then kill x endif x = dir$ loop
-- Bob Quintal
PA is y I've altered my email address.
Kill "T:\Test\" & x
The code you have will only work if t:\test is the current directory.
--
Terry Kreft
"Dixie" <di***@dogmail.com> wrote in message
news:43******@duster.adelaide.on.net... I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles()
On Error Resume Next
Dim x As String
x = Dir$("T:\Test")
Do While x <> ""
Kill x
x = Dir$
Loop
End Function
I have that code in a module and I am running it temporarily from a button with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
The method you had should work fine except you had'nt taken into account
concatenating the target directory with the file name you obtained from
Dir$.
--
Terry Kreft
"Dixie" <di***@dogmail.com> wrote in message
news:43********@duster.adelaide.on.net... I have turned my attack to a different method
Sub DeleteFilesThatIDontWant()
Dim fso
Dim sfol As String
sfol = "T:\Test"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
Else
fso.deleteFile (sfol & "\*.txt")
End If
End Sub
That will delete all the txt files, but when it comes across a ~$xxxxx.txt file which is in use, it fails to delete ANY of the files. My problem is how do I make it ignore that file and delete the others?
dixie
"Dixie" <di***@dogmail.com> wrote in message news:43******@duster.adelaide.on.net...I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles() On Error Resume Next Dim x As String x = Dir$("T:\Test") Do While x <> "" Kill x x = Dir$ Loop End Function
I have that code in a module and I am running it temporarily from a button with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
"Dixie" <di***@dogmail.com> wrote in
news:43******@duster.adelaide.on.net: I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles()
On Error Resume Next
Dim x As String
x = Dir$("T:\Test")
Do While x <> ""
Kill x
The line above should read
Kill "T:\Test" & "\" & x
--
Bob Quintal
PA is y I've altered my email address.
Thats alright, I will actually usie a DLookup to get the folder so it can be
more generic.
dixie
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:NL********************@karoo.co.uk... Kill "T:\Test\" & x
The code you have will only work if t:\test is the current directory.
-- Terry Kreft "Dixie" <di***@dogmail.com> wrote in message news:43******@duster.adelaide.on.net...I don't know what it is I'm doing wrong, but here is the exact code I am using
Function KillMergeFiles()
On Error Resume Next
Dim x As String
x = Dir$("T:\Test")
Do While x <> ""
Kill x
x = Dir$
Loop
End Function
I have that code in a module and I am running it temporarily from a button with the command KillMergeFiles.
When I run it, nothing happens to the files in that folder (there are currently 30 .txt files in there.
dixie
"MacDermott" <ma********@nospam.com> wrote in message news:8f****************@newsread3.news.atl.earthli nk.net... How about something like this: On error resume next x = dir$("C:\directory to clean") do while x<>"" kill x x = dir$ loop
Of course that assumes that the directory contains nothing but the .txt files you want to kill...
"Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
Thanks Terry, I've accepted your advice there. It is error number 70 and I
have trapped it and allowed the code to branch to an appropriate label.
Thanks to all who contributed. Appreciated.
dixie
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:NL********************@karoo.co.uk... So trap the error generated and resume next or jump to an appropriately positioned label.
There are times where you can't do anything other than use the error condition as a flag for program branching. -- Terry Kreft "Dixie" <di***@dogmail.com> wrote in message news:43********@duster.adelaide.on.net... I've got something like that working OK, except, when there is a ~$ style file, it is locked and I always get an error, even if I am just trying to jump over it and delete any other file that does not start with that character combination.
dixie
"Bob Quintal" <rq******@sympatico.ca> wrote in message news:Xn**********************@207.35.177.135... "Dixie" <di***@dogmail.com> wrote in news:43********@duster.adelaide.on.net:
I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using them, in which case they will have the first two letters of their name replaced with ~$. How can I write a routine that will delete all the normal *.txt files, but not attempt to delete the ~$ ones, which brings up an error message and prevents the program from closing. I thought this would be easy, but I have not managed to do it after quite a while trying.
dixie
Scan the directory in question using the dir() function. Then code an if block that deletes the offending files.
Untested code:
x = dir$("C:\directory to clean") do while len(x) >0 if left(x,2) <> "~$" then kill x endif x = dir$ loop
-- Bob Quintal
PA is y I've altered my email address.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sea |
last post by:
I have text files in the following format:
123,34,
,345,890,
123,23
..
..
..
As you can see, the problem is that (1) the commas can occur in
|
by: ross |
last post by:
I want to do some tricky text file manipulation on many files, but have
only a little programming knowledge.
What are the ideal languages for the following examples?
1. Starting from a certain...
|
by: David Mitchell |
last post by:
I use a function to read all of the files from a couple of directories
(and subfolders) and update a table(tblfiles) with the fullpath and
file name, the filesize and the date the file was created....
|
by: dixie |
last post by:
I am trying to delete the temporary files that MS Word leaves behind
sometimes when it fails to clean up properly. Files like ~$lename.dot. I
have used the Kill command, but find that this...
|
by: Scott |
last post by:
Hello,
I am running into a problem with my code and can't seem to figure out the
solution.
I know it has to do with the pciture box control and unloading the image
inthe picture box but I can't...
|
by: Dino Buljubasic |
last post by:
My application can allow a user to open a file for viewing by fetching
file data from database, creating the file in a temp directory and
starting appropriate process (i.e. Adobe or any other...
|
by: g0c |
last post by:
hi all,
i really cannot find a simple exmaple for preg_match function
i whiled the files in the directory ...
$d = dir('.') or die($php_errormsg);
while (false !== ($f = $d->read())) {
if...
|
by: kbperry |
last post by:
Hi all,
Background:
I need some help. I am trying to streamline a process for one of our
technical writers. He is using Perforce (version control system), and
is constantly changing his word...
|
by: Kenneth Brody |
last post by:
I recently ran into an "issue" related to text files and ftell/fseek,
and I'd like to know if it's a bug, or simply an annoying, but still
conforming, implementation.
The platform is Windows,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |