{"id":13204,"date":"2021-12-11T15:56:26","date_gmt":"2021-12-11T15:56:26","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=13204"},"modified":"2021-12-11T15:56:49","modified_gmt":"2021-12-11T15:56:49","slug":"delete-add-lines-in-txt-file-with-cmd","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/deleteadd-lines-in-txt-file-with-cmd\/23078.html","title":{"rendered":"Delete\/Add Lines In Txt File With Cmd"},"content":{"rendered":"<p>Hi there,<\/p>\n<p>I&#8217;m writing a pretty basic script with the &#8216;attrib&#8217; command to hide\/show files and folders.<br \/>\nEvery time I hide a file it should write the pathname (+ date) into a .txt file.<br \/>\nBut it also should delete the pathnames of files and objects in the .txt file if they are restored.<\/p>\n<p>If an user enters a wrong pathname then I want to enter a custom error message and being able to go back to :A<\/p>\n<p>Finaly, I was wondering if it was possible to make an perfect box with ANY username, time and date.<\/p>\n<p>Here is the script:<\/p>\n<p>@echo off<\/p>\n<p>title File Hider<br \/>\ncolor 02<br \/>\ncd C:\\Users\\Myname\\Documents\\Myname\\<br \/>\n:: (I do this because otherwise it won&#8217;t find test.txt)<br \/>\ncls<\/p>\n<p>echo.<br \/>\necho.<\/p>\n<p>echo &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\necho ^| ^|<br \/>\necho ^| Welcome %username% ^|<br \/>\necho ^| ^|<br \/>\necho ^| It is %time% ^|<br \/>\necho ^| %date% ^|<br \/>\necho ^| ^|<br \/>\necho &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>echo.<br \/>\necho.<\/p>\n<p>pause<\/p>\n<p>cls<\/p>\n<p>:A<\/p>\n<p>echo.<br \/>\necho.<\/p>\n<p>ECHO Choose Option &#8220;1&#8221; if you want to hide an object.<br \/>\nECHO Choose Option &#8220;2&#8221; if you want to make an object visible again.<br \/>\nECHO Choose Option &#8220;3&#8221; to display a list of hidden objects.<br \/>\nECHO Choose Option &#8220;4&#8221; to quit.<\/p>\n<p>echo.<br \/>\necho.<\/p>\n<p>choice.exe \/C 12345 \/N \/M &#8220;Your choice:&#8221;<\/p>\n<p>IF ERRORLEVEL == 255 GOTO FAIL<br \/>\nIF ERRORLEVEL == 5 GOTO TEST<br \/>\nIF ERRORLEVEL == 4 GOTO END<br \/>\nIF ERRORLEVEL == 3 GOTO OPEN<br \/>\nIF ERRORLEVEL == 2 GOTO SHOW<br \/>\nIF ERRORLEVEL == 1 GOTO HIDE<\/p>\n<p>echo.<br \/>\necho.<\/p>\n<p>pause<\/p>\n<p>:HIDE<br \/>\nECHO Give the pathname:<br \/>\nset \/p n=<\/p>\n<p>attrib +s +r +h %n%<\/p>\n<p>echo Object succesfull hidden!<\/p>\n<p>%n% &gt; test.txt<\/p>\n<p>echo The pathname is saved in test.txt<br \/>\npause<br \/>\ncls<\/p>\n<p>GOTO A<\/p>\n<p>:SHOW<br \/>\nECHO Enter the path:<br \/>\necho Tip: Check test.txt<br \/>\nset \/p SHOW=<\/p>\n<p>attrib -s -r -h %SHOW%<\/p>\n<p>Echo Object restored !<\/p>\n<p>pause<br \/>\ncls<\/p>\n<p>GOTO A<\/p>\n<p>:OPEN<\/p>\n<p>test.txt<\/p>\n<p>pause<br \/>\ncls<\/p>\n<p>GOTO A<\/p>\n<p>:TEST<\/p>\n<p>::<br \/>\n::setlocal<br \/>\n::for \/F &#8220;delims=&#8221; %%j in (&#8216;type &#8220;%*&#8221;&#8216;) do set line=%%j<br \/>\n::echo.%line%&gt; &#8220;%*&#8221;<br \/>\n::<\/p>\n<p>echo test<\/p>\n<p>pause<br \/>\ncls<\/p>\n<p>Goto A<\/p>\n<p>:FAIL<\/p>\n<p>echo Error ! Impossible choise.<br \/>\necho CMD closes automatically in<\/p>\n<p>Sleep 10<\/p>\n<p>cls<\/p>\n<p>end<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":7},"question-category":[55],"question_tags":[],"class_list":["post-13204","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/13204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=13204"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=13204"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=13204"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=13204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}