Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
Hello
I try to rename files using S+Net but some files can be "in use" by other program, how to get information about that in S+Net?
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
This seems to work for me, obviously it will need to be changed to suit your specific needs, but all the pieces are there: Code:var filePath = "D:\\OneDrive\\Documents\\Finances\\Budget2017.xlsx";
try {
//Attempt to open the file for exclusive access
var fs = new clr.System.IO.FileStream(filePath, clr.System.IO.FileMode.Open, clr.System.IO.FileAccess.ReadWrite, clr.System.IO.FileShare.None);
fs.Close();
}
catch(err) {
//Detect if the error is due to file being used
var inUse = err.message.indexOf("being used by another process") !== -1
sp.MessageBox(inUse, "inUse Check");
//Show the exact reason for the error
sp.MessageBox(err.message, "File Error");
}
|
1 user thanked Rob for this useful post.
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/13/2018(UTC) Posts: 54 Thanks: 18 times Was thanked: 18 time(s) in 13 post(s)
|
I really needed this script, thanks man.
|
|
|
|
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