leuce Posted November 30, 2012 Share Posted November 30, 2012 G'day everyone I'm writing a script to process some LNK files, but it is important to me that the script's actions are performed only if the LNK file links to an actual file, and not to a e.g. folder or a control panel item or suchlike. Is there a way to determine whether a full path refers to an actual file? Essentially, what I want to do is to copy the linked file from its existing location to the location of the LNK file (after I used a rather too aggressive setting on a duplicate remover program). My initial script has an @error thing (what do you call that?) that should tell me whether the file copy succeeded, but if the LNK file links to a folder instead of a file, the script tells me that the copy was a success, even though thankfully it doesn't copy the folder. I do not want it to copy folders anyway. Here is my current script, in case you're interested, although I don't think it is needed to answer my query: $lnkfile = FULL PATH TO LNK FILE $lnkfilefolder = StringRegExpReplace ($lnkfile, "\\[^\\]*$", "") $lnkdetails = FileGetShortcut($lnkfile) If Not @error Then $linkedfile = $lnkdetails[0] FileCopy ($linkedfile, $lnkfilefolder) If Not @error Then FileMove (StringTrimRight ($lnkfile, 4) & ".lnk", StringTrimRight ($lnkfile, 4) & ".copied_yes.lnk") Else FileMove (StringTrimRight ($lnkfile, 4) & ".lnk", StringTrimRight ($lnkfile, 4) & ".copied_no.lnk") EndIf EndIf Any ideas about how to do this? Thanks Samuel Link to comment Share on other sites More sharing options...
leuce Posted November 30, 2012 Author Share Posted November 30, 2012 (edited) One thing I could do, which works, is to try to change the working directory to the linked full path, and if it fails, then I know that it aint a folder. Would this be a safe thing to do, though? Should I reverse it, to be on the safe side (i.e. first determine the current working directory, then after the test change the working directory back to what it was)? [Edited: no, I tried that and it didn't work.] Samuel Edited November 30, 2012 by leuce Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 30, 2012 Moderators Share Posted November 30, 2012 FileGetAttrib Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
leuce Posted November 30, 2012 Author Share Posted November 30, 2012 FileGetAttribFantastic, thanks! Link to comment Share on other sites More sharing options...
AZJIO Posted November 30, 2012 Share Posted November 30, 2012 leuce, My other projects or all Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now