StrokesPlus.net Forum
»
General Discussion
»
General Discussion
»
How to detect the existence of a folder or file?
Rank: Member
Groups: Approved
Joined: 8/25/2019(UTC) Posts: 20 Was thanked: 1 time(s) in 1 post(s)
|
Hi, Rob.
How to detect the existence of a folder or file? I want to perform the action according to different results. Could you help me?
For example:E:\Users\abc,E:\Users\cba.txt
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
You can use the standard .NET calls for this. The only slight difference are the prefixes I have to expose them to the script engine; "clr." below. Otherwise, it's just a method of the .NET File class and Directory class. Look at the left menu of those pages to see the other methods/properties that can also be used. Most of the time, you can Google "c# how to check if file exists" and the example code will be nearly the same after converted to a script in S+; but of course there are a lot of variables and possibilities. Here's a few example scripts: Code://Escape backslashes with an extra backslash (\\)
if(clr.System.IO.Directory.Exists("C:\\Windows")) {
sp.MessageBox("C:\\Windows Folder Exists", "Found");
}
//Note the ! before clr, means NOT
if(!clr.System.IO.Directory.Exists("C:\\DoesNotExist")) {
sp.MessageBox("C:\\DoesNotExist Folder Does Not Exist", "Not Found");
}
//Can compare to true, but means the same
if(clr.System.IO.File.Exists("C:\\Windows\\win.ini") == true) {
sp.MessageBox("C:\\Windows\\win.ini File Exists", "Found");
}
//Instead of ! can compare to false
if(clr.System.IO.File.Exists("C:\\Windows\\DoesNotExist.ini") == false) {
sp.MessageBox("C:\\Windows\\DoesNotExist.ini File Does Not Exist", "Not Found");
}
Edited by user Saturday, August 31, 2019 3:28:01 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Member
Groups: Approved
Joined: 8/25/2019(UTC) Posts: 20 Was thanked: 1 time(s) in 1 post(s)
|
My problem has been solved. Thank you for your timely reply.
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
General Discussion
»
How to detect the existence of a folder or file?
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close