

InterviewSolution
Saved Bookmarks
1. |
Solve : A way to turn off the archive bit in every file in C:\? |
Answer» <html><body><p>I need a way to <a href="https://interviewquestions.tuteehub.com/tag/turn-767121" style="font-weight:bold;" target="_blank" title="Click to know more about TURN">TURN</a> off the <a href="https://interviewquestions.tuteehub.com/tag/archive-381387" style="font-weight:bold;" target="_blank" title="Click to know more about ARCHIVE">ARCHIVE</a> bit in every file in C:\ including Hidden (and maybe System) but still leave those bits as is. I would like it to run unattended after being started thought the whole directory and sub directories such as c:\.<br/><br/>I have found a MS KB #67941 which does at least the one file resetting the H bit. I assume the AND fffd can be changed to do the A bit. Then how can this be put in a batch file, or whatever, to run when desired? Or is there another better way?<br/><br/>Many thanks to anyone who can show me the way.<br/><br/>SnowmanRemove the archive switch? This code should work, but it will take a long time to process, depending on how many files you have on the C drive.<br/><br/>echo off<br/>for /f "delims=" %%a in ('dir /b /s C:\') do attrib -a "%%a"<br/>pauseThanks Helpmeh. <br/><br/>Put your suggestion in a batch file and got a syntax error. <br/><br/>Would you please explain the code. <br/><br/>How should I set it up so I can like push a button each time I want it to run.<br/><br/>SnowmanStrange...the code works for me...Although I removed the C:\ so I could run the batch file and it would remove the archive attribute in all the files in the work directory.helpmeh... all your code does is emulate the /s switch.<br/><br/>attrib has a /s switch, btw, so attrib *.* -a /s would accomplish the same thing.<br/><br/>however, the main issue here is that it will refuse to change the attributes on hidden or system files.<br/><br/>you could do:<br/><br/>attrib *.* -s -h -a /s<br/><br/><br/>but this has another problem since we don't want to permanently remove the hidden and system attributes, bringing us back to the iterative loop idea.<br/><br/><br/>Anyway, to cut a long story short I spent at least an hour trying to make a batch solution. Gave up, and then wrote a VBScript in about 5 minutes <br/><br/> Code: <a>[Select]</a>Dim FSO<br/>Dim usefolder<br/><br/>set FSO = CreateObject("Scripting.FileSystemObject")<br/><br/>set usefolder= FSO.GetFolder(CreateObject("WScript.Shell").CurrentDirectory)<br/><br/><br/>'WScript.Echo usefolder.name <br/><br/>Removearchiveattrib usefolder <br/><br/>Sub RemoveArchiveAttrib(InFolder)<br/><br/>Dim CurrFile,CurrFolder<br/><br/>For Each CurrFile in InFolder.Files<br/> if (Currfile.Attributes And 32)=32 then<br/> 'has the archive attribute, remove it.<br/> currfile.attributes = currfile.attributes-32<br/> 'WScript.echo "archive attribute found on file:" & currfile.name <br/> <br/> end if <br/><br/><br/>Next <br/>for each Currfolder in InFolder.SubFolders<br/> RemoveArchiveAttrib Currfolder <br/><br/>Next <br/><br/>End Sub<br/><br/>I tested this, and it works great for me To use it simply paste it into notepad, and then save it as a "VBS" file- preferably in the folder you wish to work with, or, even better a test folder to see if it works. then you should be able to double-click it to run it.<br/><br/>for the record, the batch code that I had (which failed to work at all) was this:<br/><br/> Code: <a>[Select]</a>SETLOCAL ENABLEDELAYEDEXPANSION<br/><br/>for /f "delims==*" %%i in ('dir /s /b /a') do (<br/>echo working on "%%i"<br/>attrib "%%i" | findstr "^A H "<br/>if not <a href="https://interviewquestions.tuteehub.com/tag/errorlevel" style="font-weight:bold;" target="_blank" title="Click to know more about ERRORLEVEL">ERRORLEVEL</a> 1 (<br/>echo file is hidden but not system %%i<br/><br/><br/>)<br/>attrib "%%i" | findstr "^A S "<br/>if not errorlevel 1 (<br/>echo file is system, but not hidden %%i<br/><br/><br/>)<br/>attrib "%%i" | findstr "^A SH "<br/>if not errorlevel 1 (<br/>echo file is system and hidden %%i<br/><br/>)<br/><br/><br/><br/><br/>)<br/>attrib %0.bat -h -s<br/>there were attrib commands in each block which basically removed the attribute it discovered, removed the archive attribute, and then set back the original attributes. problem was the last test for system AND hidden was always true so it would end up with both System and hidden regardless of the original attributes. It wouldn't ahve the archive attribute anymore, though. So At least there was that.<br/><br/>Thank you BC_Programmer for spending so much time. I really appreciate it when someone spends time to really try to help rather that a short incomplete answer or really just a clue that seldom is enough to know where to go next.<br/><br/>I have done what you recommend to the point that this old Dell GX-1 with Win 98II does not have the VB Scripting installed. Also the help for VBA editor is missing also. I will have to get the installation disk sent to me from home in Massachusetts. I am wintered here in Arizona. Will post after I get that installed. Is your script good for Excel 2000? <br/><br/>I using this Dell Studio 1737 Vista 64 for most everything else. The reason from maintaining the 98 machine is the need for the serial port to download from a data logger that won't work with any USB adapter.<br/><br/>Just for kicks the following is the Debug routine in the MS KB. The fffd would need to be adjusted to select the Archive bit. I tried changing it to dfff but am not sure of that:<br/><br/>The method described below uses DEBUG to create a small program that removes the hidden attribute from a file. This method should be used only as a last resort. <br/>At the MS-DOS prompt, type the following commands: <br/> DEBUG<br/> A 100<br/> mov dx,116<br/> mov ax,4300<br/> <br/> int 21<br/> and cx,fffd<br/> mov dx,116<br/> mov ax,4301<br/> int 21<br/> int 20<br/> <br/> E 116 'filename' 0 <------- replace "filename" with the path<br/> G and filename of the target file.<br/> Example: e 116 'C:\DATA\TEST.DAT' 0<br/> <br/><br/>When you type the command "G," DEBUG executes the section of code in memory. If you have typed everything correctly, the message "Program terminated normally" is displayed. <br/>Type Q to quit DEBUG, then verify that the file is no longer hidden. <br/>Back to the top<br/>Code Explanation<br/><br/><br/>The following is a detailed description of the preceding code: <br/>mov dx,116 ; load the offset to filename into dx<br/>mov ax,4300 ; load get/set file attributes function number into ax<br/> <br/>int 21 ; call DOS interrupt 21H to read attribute information<br/> <br/>and cx,fffd ; strip off only hidden attribute bit<br/>mov dx,116 ; load the offset to filename into dx<br/>mov ax,4301 ; load get/set file attributes function number into ax<br/> <br/>int 21 ; call DOS interrupt 21H to write attribute information<br/>int 20 ; terminate program<br/> <br/><br/>The program begins by calling Int 21H function 43H to get the current file attribute. The attribute byte is returned in register CX, which is then ANDed with hex FFFD to reset bit 1. The program calls the get/set file attribute function again to write the attribute in register CX to the file. Quote</p><blockquote>I have done what you recommend to the point that this old Dell GX-1 with Win 98II does not have the VB Scripting installed.<br/></blockquote> <br/>Win 98SE <a href="https://interviewquestions.tuteehub.com/tag/includes-1039937" style="font-weight:bold;" target="_blank" title="Click to know more about INCLUDES">INCLUDES</a> VBScript and the ActiveX Scripting Host.<br/><br/>It might work with VBA, but VBA is totally different from VBScript, which, comes with the OS. unless you purposely uninstalled it it should still be there.<br/><br/>Not sure exactly what is going on with the debug scripts(despite your thorough explanation, I'm dreadfully sleepy at the moment <em>EDIT: and no, not because of the explanation.... </em>), but the archive attribute is hexadecimal 20... so, removing the archive attribute from FFFF would give you FFDF, which may work in place of the fffd you tried.<br/><br/><br/><br/><br/>Thanks again.<br/><br/>I searched and only found "Vbscript.dll" on the disk. While years ago in my business I ran a unix system with a very powerful Business Basic App and used the Korn Shell frequently and have some very limited experince with VBA I have never used VBScript. If I start it what will I see to tell me it is running? Will it run through the complete c:\ directory each time or will it make adifference where I start it. I tried it on a test disk and it didn't give an error but don't know if it is doing anything or not. <br/><br/>Is there a site on line that will give me enough information to understand the instructions, variables etc. to be able to run VBScipt and program with it?<br/><br/>Snowman Quote<blockquote>To use it simply paste it into notepad, and then save it as a "VBS" file- preferably in the folder you wish to work with, or, even better a test folder to see if it works. then you should be able to double-click it to run it.<br/></blockquote> <br/>It runs through the folder it's in.It appears to work fine. I just needed to copy the script to a file in the directory I want to clear before running it.<br/><br/>Where can quickly find more information to use VBS?<br/><br/>Again, Thanks for the extraordinary help.<br/><br/>Snowman Quote from: Snowman on February 19, 2010, 04:15:54 PM<blockquote>Where can quickly find more information to use VBS?<br/></blockquote> <br/>the MS <a href="https://interviewquestions.tuteehub.com/tag/reference-1181544" style="font-weight:bold;" target="_blank" title="Click to know more about REFERENCE">REFERENCE</a> material can be found <a href="https://msdn.microsoft.com/en-us/library/t0aew7h6%28VS.85%29.aspx">here</a>.<br/><br/>First it's important to know the various "dialects" of the core Visual Basic language.<br/><br/>First, we had "plain" Visual Basic, which was a development tool for windows. With a few changes any VBScript designed code or VBA code can usually be convinced to run in it.<br/><br/>VBA is a version of Visual Basic that is used by office to create macros; it's almost identical to the "full" Visual Basic version, except all code is inside of the word/excel/powerpoint/etc document structure and it doesn't use the Visual basic runtime, so stuff from that run-time (a good number of functions and constants_ that you can use in the "full" visual basic product are unavailable in VBA.<br/><br/>VBScript is essentially a "scriptified" version of Visual Basic. a large number of things were removed for a number of reasons. The idea was to replace the older batch code method of automating tasks with a "windows" version that was called the "windows script host" model. By default the Windows Script Host (WSH) allows you to use VBScript or Javascript to automate tasks, such as the VBScript I provided.<br/><br/>You seem like your at least a little familar with the command line, so this might interest you. you can run Scripts from the commandline, and you can use "CScript.exe" which runs the script in a manner that allows it to output to the console, or via "WScript.exe" which will display messages boxes for most output functions and input functions, but does not create or use a command line window.<br/><br/> Quote<blockquote>Again, Thanks for the extraordinary help.<br/><br/></blockquote> your welcome <br/><br/></body></html> | |