473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

newby - Help with FILE.DELETE

I'm trying to delete a file with

File.Delete("c:\Documents and Settings\%username%\Application
Data\Microsoft\Excel\excel*.xlb")

On doing this I get an Exception "Illegal characters in path" - I assume its
the %username% bit

I trierd

Dim UserName As String %username%
File.Delete("c:\Documents and Settings\" & UserName & "\Application
Data\Microsoft\Excel\excel*.xlb")

Still get the same error

How can I get the Username from the system !!???
Nov 21 '05 #1
8 2671
% is integer is valid for vb.net
can u remove %?
DavidB wrote:
I'm trying to delete a file with

File.Delete("c:\Documents and Settings\%username%\Application
Data\Microsoft\Excel\excel*.xlb")

On doing this I get an Exception "Illegal characters in path" - I assume its
the %username% bit

I trierd

Dim UserName As String %username%
File.Delete("c:\Documents and Settings\" & UserName & "\Application
Data\Microsoft\Excel\excel*.xlb")

Still get the same error

How can I get the Username from the system !!???


Nov 21 '05 #2
To get an environment variable, use Environment.GetEnvironmentVariable()
method

To get access to the special folder, you can also use the
Environment.GetFolderPath() Method

- José
"Supra" <su*****@rogers.com> a écrit dans le message de news:
%2****************@TK2MSFTNGP10.phx.gbl...
% is integer is valid for vb.net
can u remove %?
DavidB wrote:
I'm trying to delete a file with

File.Delete("c:\Documents and Settings\%username%\Application
Data\Microsoft\Excel\excel*.xlb")

On doing this I get an Exception "Illegal characters in path" - I assume
its
the %username% bit

I trierd

Dim UserName As String %username%
File.Delete("c:\Documents and Settings\" & UserName & "\Application
Data\Microsoft\Excel\excel*.xlb")

Still get the same error

How can I get the Username from the system !!???

Nov 21 '05 #3
David,

"DavidB" <davidb@notreally_hotmail.com> schrieb:
I'm trying to delete a file with

File.Delete("c:\Documents and Settings\%username%\Application
Data\Microsoft\Excel\excel*.xlb")

On doing this I get an Exception "Illegal characters in path" - I assume
its
the %username% bit

I trierd

Dim UserName As String %username%
File.Delete("c:\Documents and Settings\" & UserName & "\Application
Data\Microsoft\Excel\excel*.xlb")


AFAIK 'File.Delete' does not support wildcards ("*", in this particular
case). The code below is untested, but it should give you an idea on how to
solve the problem:

\\\
Imports System
Imports System.IO
..
..
..
Dim FileNames() As String = _
Directory.GetFiles( _
Path.Combine( _
Environment.GetFolderPath( _
Environment.SpecialFolder.LocalApplicationData _
), _
"Microsoft\Excel\excel*.xlb" _
) _
)
For Each FileName As String In FileNames
File.Delete(FileName)
Next FileName
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
"Supra" <su*****@rogers.com> schrieb:
% is integer is valid for vb.net
can u remove %?


I assume the OP wanted to type 'Dim UserName As String = '"%username%"'. So
there is no integer...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
"José Joye" <jo*************************************@bluewin.c h> schrieb:
To get an environment variable, use Environment.GetEnvironmentVariable()
method


ACK. Alternatively you can use 'Environment.ExpandEnvironmentVariables' to
expand all environment variables which are contained in a certain string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
Hi,

Dim UserName As String = Environment.UserName

Ken
---------------------
"DavidB" <davidb@notreally_hotmail.com> wrote in message
news:uf**************@tk2msftngp13.phx.gbl...
I'm trying to delete a file with

File.Delete("c:\Documents and Settings\%username%\Application
Data\Microsoft\Excel\excel*.xlb")

On doing this I get an Exception "Illegal characters in path" - I assume its
the %username% bit

I trierd

Dim UserName As String %username%
File.Delete("c:\Documents and Settings\" & UserName & "\Application
Data\Microsoft\Excel\excel*.xlb")

Still get the same error

How can I get the Username from the system !!???

Nov 21 '05 #7
DavidB,

I am in doubt about your question is it FILE.DELETE or how to concatinate a
string, or how to get the username best way to get the applicationData
folder from the current user.

The first answer is,
In the way you do that.

The second answer is (see the next answer)
" & myUsername & "

The third answer is
dim myUsername = environment.username

The fourth answer is:
dim mypath as string =
Environment.GetFolderPath(Environment.SpecialFolde r.ApplicationData)

I hope this helps?

Cor
Nov 21 '05 #8
Good to know :-)

- José
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news: e5**************@TK2MSFTNGP15.phx.gbl...
"José Joye" <jo*************************************@bluewin.c h> schrieb:
To get an environment variable, use Environment.GetEnvironmentVariable()
method


ACK. Alternatively you can use 'Environment.ExpandEnvironmentVariables'
to expand all environment variables which are contained in a certain
string.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: charlie fortune | last post by:
I have a simple html form and a bit of PHP in the same page, and I want the script to get the entry from the form, and write it to a file. I dont think I'm allowed to use POST on my webspace. Here...
9
by: Damien | last post by:
I have just built a simple stopwatch application, but when i f5 to get things goings i get this message, An unhandled exception of type 'System.ArithmeticException' occurred in...
0
by: Pete | last post by:
Hi All, A total Newby with, possibly, a daft question? However, until I can get a reasonable explanation I am disinclined towards going further. Here goes: I recently downloaded the latest...
0
by: marco | last post by:
I'm trying to parse a xml bookmarkpage with php. I found a very useful example script about how you can parse a xml document with php. The scriptworks really smooth. The xml test document (See...
8
by: Ask | last post by:
G'day All, Just thought I'd drop in and say hi. I'm new to Python, but old to software development. Python is one of the languages used in my new job, so I've just bought a book, read it, and...
10
by: Fred Nelson | last post by:
Hi: I have programmed in VB.NET for about a year and I'm in the process of learing C#. I'm really stuck on this question - and I know it's a "newby" question: In VB.NET I have several...
3
by: Fred Nelson | last post by:
Hi: I have created a datatable and I'm able to access it by key values. I need to be able to go to the "top" of the datatable and process records sequentially until they are completed. I...
1
by: James Johnston | last post by:
I've never written a Python program before and I'm trying to read a config file with file path/names (eg. c:\\python24\\*.dll, ... *.exe) to create an output file of filename + md5 values. I'm...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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
tracyyun
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...
0
agi2029
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 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.