简体   繁体   中英

set file attribute filesystemobject javascript

I have created a file as part of a script on a network drive and i am trying to make it hidden so that if the script is run again it should be able to see the file and act on the information contained within it but i am having trouble doing this. what i have so far is:

function doesRegisterExist(oFs, Date, newFolder) {
    dbEcho("doesRegisterExist() triggered");
    sExpectedRegisterFile = newFolder+"\\Register.txt"
    if(oFs.FileExists(sExpectedRegisterFile)==false){
        newFile = oFs.OpenTextFile(sExpectedRegisterFile,8,true)
        newFile.close()
        newReg = oFs.GetFile(sExpectedRegisterFile)
        dbEcho(newReg.Attributes)
        newReg.Attributes = newReg.Attributes+2
    }

}

Windows Script Host does not actually produce an error here and the script runs throgh to competion. the only guides i have found online i have been attempting to translate from VBscript with limited success.

variables passed to this function are roughly declared as such

var oFs = new ActiveXObject("Scripting.FileSystemObject")
var Date = "29-12-2017"
var newFolder = "\\\\File-Server\\path\\to\\folder"

I know ActiveX is a dirty word to a lot of people and i should be shot for even thinking about using it but it really is a perfect fit for what i am trying to do.

Please help.

sExpectedRegisterFolder resolves to \\\\\\\\File-Server\\\\path\\\\to\\\\folder\\\\Register which is a folder and not a file.

I get an Error: file not found when I wrap the code into a try/catch block.

I tested the code on a text file as well, and there it works.

So you're either using the wrong method if you want to set the folder to hidden. Or you forgot to include the path to the text if you want to change a file to hidden. ( Edit: Or if Register is the name of the file, add the filetype .txt ? )

If you change GetFile to GetFolder as described in https://msdn.microsoft.com/en-us/library/6tkce7xa(v=vs.84).aspx the folder will get hidden correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM