Redirecting command output to a hidden file!!

SwathiSree
SwathiSree used Ask the Experts™
on
hi,
the command
Command > filename.txt is the way to redirect the output to a file
How do i redirect the output to hidden file??
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Commented:
If the file already exists and is hidden, you will need to "unhide" it first, then redirect the command output to it, then rehide it after.  The ATTRBI command is used to control file attributes including the HIDDEN attribute.  For example:

ATTRIB -H filename.txt
ECHO Hello > filename.txt
ATTRIB +H filename.txt

If the file is a new file that doesn't exist and you just want to make it hidden after writing to it then all you need is this:

ECHO Hello > filename.txt
ATTRIB +H filename.txt

Hope this helps.

~bp
BTW, just one addition: If you want to append redirected output using >> you don't need to first unhide the file, >> works well for hidden files.

Author

Commented:
thanks for the replies.

i want to create the file with hidden attribute set in a single command. Is that possible?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
No, that is not possible, it takes two commands, but why is that a problem, they will happen essential at the same time.

~bp

Commented:
The tags of this question are:
 MS DOS, Bourne-Again Shell (bash)

What is your system? MS-DOS? What is your command interpreter? bash???
Unless you know the system, you can't say anything about "hidden" files.

Author

Commented:
My system is Win 7
MS-DOS
comand prompt
A single LINE or a single Function?

This is a single function, albeit using several different commands within it:

if exist filename.txt (
    attrib -h filename.txt & echo Hello > filename.txt & attrib +h filename.txt
    ) else (
    echo Hello > filename.txt & attrib +h filename.txt
)

I don't see anything wrong with the suggestions by bill prew or Zoppo though.
Deepu AbrahamR & D Engineering Manager

Commented:
ATTRIB -R -A -S -H "file name"

ATTRIB +R +A +S +H "file name "

+ will turn the attributes on/ - will turn the attributes off

Author

Commented:
I had to ask a follow-up question

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial