Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help setting file attribute to HIDDEN 2

Status
Not open for further replies.

tlogan

Programmer
Jun 26, 2001
33
0
0
US
Hello All!

I've gotten some great help here and I hope someone can come through for me (again!).

I'm trying to create a text file and set it to HIDDEN (Attributes =2). I've found several references on how to do it, but none of them seem to work. Here is my code. It works perfectly if I DON'T try to set the file attributes to HIDDEN.

Thanks,
TLogan

NOTE!!! Names have been changed to protect the innocent! Actual IP address and directories are correct in my code. For obvious reasons I have to mask them here. Also, the USER ID and Password are entered into an HTML form earlier in the script.
Code:
'******************************************************
' create a hidden text file to use in the FTP procedure
 Dim oFSo, scriptFile
 
 Set oFSo = CreateObject("Scripting.FileSystemObject")
 Set scriptFile = oFSo.CreateTextFile("C:\Temp\script.ftp")
[b] Set scriptFile.Attributes = 2 [/b]
'******************************************************
'  Write to the script file for FTP down from site
 scriptFile.writeline("USER " & strID)
 scriptFile.writeline(strPassword) 
 scriptFile.writeline("cd TO/Some/New/directory/")
 scriptFile.writeline("binary")
 scriptFile.writeline("prompt n")
 scriptFile.writeline("lcd "  """C:/Temp/files""")
 scriptFile.writeline("mget *.*")
 scriptFile.writeline("quit")
 scriptFile.close

 Set Script=WScript.CreateObject("WScript.Shell")
  
 Script.Run "ftp -n -s:script.ftp 99.99.99.99", 0, True
 Wscript.Echo "Files Copied"

 Script.Run "%COMSPEC% /c del c:\Temp\script.ftp /q/f",0,true
END SUB
 
Set scriptFile.Attributes = 2
Get rid of the Set instruction, like this:
scriptFile.Attributes = 2

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks PHV -

Still no go. I thought I had tried that in the first place, but when it didn't work went to the "set" syntax. But, I tried it again and still nothing.

I notice also that when I try to set the scriptFile.Attribute in ANY way and run the script, the script does not appear to encounter any errors (ie, it runs to completion) EXCEPT that the scriptFIle is NOT hidden, and nothing is written to it. If I comment out the scriptFile.Attributes, it runs to completion and the scriptFile IS written to, but still not Hidden.

Does that help clarify what is going on or give you (or anyone else) any other ideas?

Thanks,
TLogan
 
Hello tlogan,

The reason that scriptfile.attributes results in error is because scriptfile, the way you create it, is actually a textstream which is different from a file (fileitem) object. The latter supports attributes property & hidden is read-write ok. Hence to set it, do this.
Code:
'******************************************************
' create a hidden text file to use in the FTP procedure
 Dim oFSo, scriptFile
 
 Set oFSo = CreateObject("Scripting.FileSystemObject")
 Set scriptFile = oFSo.CreateTextFile("C:\Temp\script.ftp", true)
 
'******************************************************
'  Write to the script file for FTP down from site
 scriptFile.writeline("USER " & strID)
 scriptFile.writeline(strPassword) 
 scriptFile.writeline("cd TO/Some/New/directory/")
 scriptFile.writeline("binary")
 scriptFile.writeline("prompt n")
 scriptFile.writeline("lcd "  """C:/Temp/files""")
 scriptFile.writeline("mget *.*")
 scriptFile.writeline("quit")
 scriptFile.close
 Set scriptFile = oFSo.GetFile("C:\Temp\script.ftp")
 scriptFile.attributes = 2
Note: I added overwrite true, else repeated execution of the same script results in error on that line.

regards - tsuji
 
Thanks tsuji!

That did the trick. The file is created hidden.

BUT, now the delete doesn't work. Any ideas why that would change?

Tlogan
 
Tlogan,

This is one thing I too wonder why you need to run a dos session to delete. In fact, fso has deletefile method. So the rest of the sub can be this.
Code:
Set Script=WScript.CreateObject("WScript.Shell")
  
 Script.Run "ftp -n -s:script.ftp 99.99.99.99", 0, True
 Wscript.Echo "Files Copied"

 oFSo.DeleteFile "C:\Temp\script.ftp"
- tsuji
 
Thanks again tsuji!

This works GREAT! I think because of the earlier problem (that you helped me fix) it was the only way I could get it work. This is MUCH cleaner way to do it.

Thanks again!

You get my vote!

TLogan
 
Try this:
scriptFile.Delete True

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PHV -

Thanks for the help. That works, too. I guess it's a matter of preference. I think I'll use your way, because it reads easier in the code. Once the file is created as "scriptfile" all other references to that object are as "scripfile.something" so it is quite clear what is being deleted without having to look at (and re-type) the file name.

Have you figured out what I'm trying to do? You helped me last week trying to create a batch file to execute a bunch of Excel spreadsheets. Since I didn't know anything about batch files or WSH, I figured the batch file was the fast, easy way. Now that I have that working, I thought I'd convert it over to WSH, since it handles Passwords more elegantly (fire up an IE session and use an HTML form) and is likely to be more portable in the future.

AND I get to add something new to my resume!

OK, I'll vote for you too!

Thanks,
TLogan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top