Quick Search for:  in language:    
Suppose,apppath,Drive,result,another,director
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,011,557. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
Files Comperator (the right way)
By Jarry Claessen on 6/30


Simple UDP example
By Mick Walton on 6/30


CAPS Trigger
By Trevor Burley on 6/30


Auto clip picture
By Kenneth. Jakobsen on 6/30


Click here to see a screenshot of this code!Game of life clone (cool math)
By Johannes B on 6/30

(Screen Shot)

String to CHR()
By Nikhil Raj on 6/30


Encryption Decryption Demo
By Nikhil Raj on 6/30


Click here to see a screenshot of this code!Serial Registration
By Christian (eXonite Team) on 6/30

(Screen Shot)

AniViewer
By Jerrame Hertz on 6/30


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Detect "\" in directory

Print
Email
 

Submitted on: 8/17/2000 10:37:46 PM
By: Eric LeBourgeois  
Level: Beginner
User Rating: By 3 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this code 6321 times.
 
(About the author)
 
     Suppose You try to get the app.path when the app is in the C Drive. the result is "C:\". if the app is in another directory the result may be "C:\Directory". notice there is no backslash. most people skip this because they don't think it is a problem, but it is. when you put in a program, app.path & "\filename.file", when it is in the C Drive or if you put app.path & "filename.file" in a named directory, the computer will either return "C:\\filename.file" or "C:\Directoryfilename.file". this code will show you how to detect the backslash and deal with it.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Detect "\" in directory
' Description:Suppose You try to get the
'     app.path when the app is in the C Drive.
'     the result is "C:\". if the app is in an
'     other directory the result may be "C:\Di
'     rectory". notice there is no backslash. 
'     most people skip this because they don't
'     think it is a problem, but it is. when y
'     ou put in a program, app.path & "\filena
'     me.file", when it is in the C Drive or i
'     f you put app.path & "filename.file" in 
'     a named directory, the computer will eit
'     her return "C:\\filename.file" or "C:\Di
'     rectoryfilename.file". this code will sh
'     ow you how to detect the backslash and d
'     eal with it.
' By: Eric LeBourgeois
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=10775&lngWId;=1'for details.'**************************************

'this code will give you a valid filenam
'     e, whether the app.path return has a bac
'     kslash or not, and displays a message bo
'     x.
'Please Vote for me at Planet Source Cod
'     e

If right(app.path,1) = "\" Then 'sees if the directory has a backslash at the End of it
    MsgBox app.path & "filename.file"
    Goto ResumeMe
End If

MsgBox app.path & "\filename.file" ResumeMe:


Other 5 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/18/2000 5:28:03 AM:M.I.X
Hmm nice way..
But i 
use..
len(app.path) > 3 then
app.path & "\filename.file"
else
app.path & "filename.file"
end 
if
Hmm But it works.
yours M.I.X
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/18/2000 5:29:44 AM:M.I.X
Sorry Here is the complet code 
:-)
>>>Hmm nice way..
But i 
use..
If len(app.path) > 3 
then
app.path & 
"\filename.file"
Else
app.path & 
"filename.file"
End If
Hmm But it 
works.
yours M.I.X
 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/18/2000 5:57:38 AM:jparks
Eric, you really shouldn't vote for 
yourself.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/18/2000 8:53:34 AM:Fastgraph boy
dim AppPath as string
if 
RIGHT(App.Path,1)="\" then
AppPath=App.Path
else
AppPath=App.Path & "\"
END IF
OPEN 
AppPath & Filename FOR INPUT AS #1
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/18/2000 2:56:54 PM:Eric LeBourgeois
sorry, i didn't vote for myself, one of 
my friends knows my password and he 
renames things and puts useless 
pictures as screenshots. i'll try not 
to let that happen again.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/18/2000 8:44:01 PM:BST
M.I.X. - Your code works. The problem 
comes in if you put this into a 
function and just pass the path to it. 
Use Eric's code and you can pass a path 
from App.Path, or any method that will 
generate a path. I've seen some methods 
that will return a path with a 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/18/2000 8:44:53 PM:BST
M.I.X. - Your code works. The problem 
comes in if you put this into a 
function and just pass the path to it. 
Use Eric's code and you can pass a path 
from App.Path, or any method that will 
generate a path. I've seen some methods 
that will return a path with a "\" and 
some that don't. (Bring VBA and 
VBScript into the situation and you'll 
run into this problem)
Eric's is a 
more reliable way.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/17/2000 7:43:54 AM:Tom Walker
A better way would be:
Dim fso As New 
FileSystemObject
fso = 
CreateObject("Scripting.FileSystemObject
")
AppPath = fso.BuildPath(App.Path, 
filename)
MsgBox AppPath
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/21/2000 9:48:03 PM:CoryUlui
I like both all your ways, all work. 
I like M.I.X way somewhat more. But I 
used to use Eric's. ;)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/30/2000 5:03:59 PM:RML
This won the contest????????????
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/20/2000 1:11:41 AM:Thomas...
It can be done this way 
too...
DirectoryPath = 
Replace(App.path & 
"\FileName","\\","\")
: )
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/21/2000 2:52:49 PM:Eric LeBourgeois
when did i win?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/6/2002 5:56:21 AM:Jim Limborg (Minnesota)
Hello, I've tried to paiste many of 
your code examples in my VISUAL BASIC 6 
application and none of them work.  All 
of the IF statements above turn RED in 
my Visual Basic code section.  Visual 
Basic doesn't accept it for some 
reason.  Shouldn't your codes be put in 
a PRIVATE SUB or something?  Can an IF 
statement just be put in the code all 
by itself?  I have a lot of statements 
like this: 
Picture1 = 
LoadPicture(App.Path & "\videos\" & 
"BG_VIDEOS.jpg")
The path statement 
above is in my FORM LOAD area.  I have 
many COMMAND BUTTONS that have path 
statements like:
Picture1 = 
LoadPicture(App.Path & "\" & 
"BG_BCC.jpg")
I need a PATH FIX so 
when I try running my program from a 
cdrom, it stops adding that EXTRA '\' 
in there.  It keeps searching for g:\\ 
not g:\
EXACTLY what is the code I 
should use that can be put at the 
beginning of my source code so ALL of 
my 100 or so path statements will 
work?
THANKS
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/8/2002 1:49:58 PM:Jim Limborg
A programmer by the name of DAVE TETENS 
wrote this for me.
FIRST, put the 
code below at the top of your 
FORM_LOAD:
Pth = App.Path
If 
Right(Pth, 1) = 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/8/2002 1:51:00 PM:Jim Limborg
A programmer by the name of DAVE TETENS 
wrote this for me.
FIRST, put the 
code below at the top of your 
FORM_LOAD:
Pth = App.Path
If 
Right(Pth, 1) = "\" Then
    Pth = 
Left(Pth, Len(Pth) - 1)
End If
Dave 
added this code below to the very top 
of my module code in my visual basic 6 
program.  I'm guessing you can also add 
this code to the very top of your MAIN 
FORM's code:
Option Explicit
Global 
Pth As String
Below is an example of 
one of my PATH statements:
Picture1 = 
LoadPicture(Pth & "\videos\" & 
"BG_VIDEOS.jpg")  
Notice the Pth in 
my path statement above.  It use to say 
App.Path, but I changed it to Pth 
instead.  You HAVE to change all of 
your App.Path to Pth to make this code 
work, BUT don't accidentally change the 
App.Path in the first main code I 
listed above that goes into your 
FORM_LOAD area.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/8/2002 1:54:13 PM:Jim Limborg
MY CODE ABOVE makes your program run 
even if it is stored in the root of a 
drive like C:\ or on a CDROM drive.  My 
program ran fine from my computer, but 
when I copied it to a cdr disk and 
tried running my program from the cdrom 
drive, I got a PATH NOT FOUND error 
cause and EXTRA \ was being added to my 
path statements.  MY CODE ABOVE fixes 
the problem.  I’ve tried all of 
the codes above mine, and none of them 
worked.  I think they don’t have 
ALL of the instructions to make them 
work perfect.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/31/2002 11:10:04 AM:Wolfsinc
I usually use the following:
pth = 
iif(right(app.path,1) <> "/",app.path & 
"\" & "FileName.TXT",app.path & 
"FileName.TXT")
I use this because 
it is one line of code, it is clean and 
reliable.  Of course I also come from a 
C programming world, so I got used to 
it there.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/2/2003 5:23:56 AM:Max Powers
If Right(App.Path,1) <> "\" Then Tmp = 
"\"
MsgBox App.Path & Tmp
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.