1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I changed it so that it saves it as a .txt file rather than a file and the file is appearing correctly in the desired folder but is still not hidden
Can you update your code then? Since I get confused between newFile and newReg. I assume newFile has to be set to hidden, so I don't understand why there's a newReg variable as well that tries to get hidden. I'd expect the code to be: newFile = oFs.OpenTextFile(sExpectedRegisterFolder,8,true); newFile.close(); newFile.Attributes = newFile.Attributes + 2;.
updated; i didnt think i could do that where newFile is being used for creating and editing whereas New Reg goes and gets the actual file. wouldnt that be like doing oFs.OpenTextFile(sExpectedRegisterFolder,8,true).GetFile.Attributes would that work?
You're right. You have to GetFile the newly created file again to edit its attributes. YOur code as it's written now, should work at first sight.
Hmm, i have just realised that i am unable to manually set files/folders to hide in the location i am trying to do this, but can on my desktop. perhaps this is a network permissions issues, i will have a word with my network admin
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.