StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Yuichi  
#1 Posted : Tuesday, May 28, 2019 6:14:44 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 54
Poland

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?
Rob  
#2 Posted : Tuesday, May 28, 2019 8:08:09 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
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");
}
thanks 1 user thanked Rob for this useful post.
Yuichi on 5/29/2019(UTC)
Yuichi  
#3 Posted : Wednesday, May 29, 2019 2:38:21 PM(UTC)
Yuichi

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/13/2018(UTC)
Posts: 54
Poland

Thanks: 18 times
Was thanked: 18 time(s) in 13 post(s)
I really needed this script, thanks man.
Users browsing this topic
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.