Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: A way to turn off the archive bit in every file in C:\  (Read 24756 times)

0 Members and 1 Guest are viewing this topic.

Snowman

    Topic Starter


    Greenhorn

    A way to turn off the archive bit in every file in C:\
    « on: February 18, 2010, 04:36:30 PM »
    I need  a way to turn off the archive 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:\.

    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?

    Many thanks to anyone who can show me the way.

    Snowman

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: A way to turn off the archive bit in every file in C:\
    « Reply #1 on: February 18, 2010, 04:44:18 PM »
    Remove 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.

    @echo off
    for /f "delims=" %%a in ('dir /b /s C:\') do attrib -a "%%a"
    pause
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Snowman

      Topic Starter


      Greenhorn

      Re: A way to turn off the archive bit in every file in C:\
      « Reply #2 on: February 18, 2010, 05:28:48 PM »
      Thanks Helpmeh.

      Put your suggestion in a batch file and got a syntax error.

      Would you please explain the code.

      How should I set it up so I can like push a button each time I want it to run.

      Snowman

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: A way to turn off the archive bit in every file in C:\
      « Reply #3 on: February 18, 2010, 05:34:34 PM »
      Strange...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.
      « Last Edit: February 18, 2010, 05:45:40 PM by Helpmeh »
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: A way to turn off the archive bit in every file in C:\
      « Reply #4 on: February 18, 2010, 07:37:04 PM »
      helpmeh... all your code does is emulate the /s switch.

      attrib has a /s switch, btw, so attrib *.* -a /s would accomplish the same thing.

      however, the main issue here is that it will refuse to change the attributes on hidden or system files.

      you could do:

      attrib *.* -s -h -a /s


      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.


      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 :P

      Code: [Select]
      Dim FSO
      Dim usefolder

      set FSO = CreateObject("Scripting.FileSystemObject")

      set usefolder= FSO.GetFolder(CreateObject("WScript.Shell").CurrentDirectory)


      'WScript.Echo usefolder.name

      Removearchiveattrib usefolder

      Sub RemoveArchiveAttrib(InFolder)

      Dim CurrFile,CurrFolder

      For Each CurrFile in InFolder.Files
      if (Currfile.Attributes And 32)=32 then
      'has the archive attribute, remove it.
      currfile.attributes = currfile.attributes-32
      'WScript.echo "archive attribute found on file:" & currfile.name

      end if


      Next
      for each Currfolder in InFolder.SubFolders
      RemoveArchiveAttrib Currfolder

      Next

      End Sub

      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.

      for the record, the batch code that I had (which failed to work at all) was this:

      Code: [Select]
      SETLOCAL ENABLEDELAYEDEXPANSION

      for /f "delims==*" %%i in ('dir /s /b /a') do (
      echo working on "%%i"
      attrib "%%i" | findstr "^A  H "
      if not errorlevel 1 (
      echo file is hidden but not system %%i


      )
      attrib "%%i" | findstr "^A  S "
      if not errorlevel 1 (
      echo file is system, but not hidden %%i


      )
      attrib "%%i" | findstr "^A  SH "
      if not errorlevel 1 (
      echo file is system and hidden %%i

      )




      )
      attrib %0.bat -h -s
      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.

      I was trying to dereference Null Pointers before it was cool.

      Snowman

        Topic Starter


        Greenhorn

        Re: A way to turn off the archive bit in every file in C:\
        « Reply #5 on: February 19, 2010, 12:37:53 PM »
        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.

        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?

        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.

        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:

        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.
        At the MS-DOS prompt, type the following commands:
           DEBUG
           A 100
           mov dx,116
           mov ax,4300
         
           int 21
           and cx,fffd
           mov dx,116
           mov ax,4301
           int 21
           int 20
           <ENTER>
           E 116 'filename' 0   <------- replace "filename" with the path
           G                             and filename of the target file.
                                         Example: e 116 'C:\DATA\TEST.DAT' 0
                          

        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.
        Type Q to quit DEBUG, then verify that the file is no longer hidden.
        Back to the top
        Code Explanation


        The following is a detailed description of the preceding code:
        mov dx,116     ; load the offset to filename into dx
        mov ax,4300    ; load get/set file attributes function number into ax
         
        int 21         ; call DOS interrupt 21H to read attribute information
         
        and cx,fffd    ; strip off only hidden attribute bit
        mov dx,116     ; load the offset to filename into dx
        mov ax,4301    ; load get/set file attributes function number into ax
         
        int 21         ; call DOS interrupt 21H to write attribute information
        int 20         ; terminate program
                    

        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.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: A way to turn off the archive bit in every file in C:\
        « Reply #6 on: February 19, 2010, 01:11:24 PM »
        Quote
        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.

        Win 98SE includes VBScript and the ActiveX Scripting Host.

        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.

        Not sure exactly what is going on with the debug scripts(despite your thorough explanation, I'm dreadfully sleepy at the moment EDIT: and no, not because of the explanation.... :P), 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.




        I was trying to dereference Null Pointers before it was cool.

        Snowman

          Topic Starter


          Greenhorn

          Re: A way to turn off the archive bit in every file in C:\
          « Reply #7 on: February 19, 2010, 02:50:57 PM »
          Thanks again.

          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.

          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?

          Snowman

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: A way to turn off the archive bit in every file in C:\
          « Reply #8 on: February 19, 2010, 02:57:48 PM »
          Quote
          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.

          It runs through the folder it's in.
          I was trying to dereference Null Pointers before it was cool.

          Snowman

            Topic Starter


            Greenhorn

            Re: A way to turn off the archive bit in every file in C:\
            « Reply #9 on: February 19, 2010, 04:15:54 PM »
            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.

            Where can quickly find more information to use VBS?

            Again, Thanks for the extraordinary help.

            Snowman

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: A way to turn off the archive bit in every file in C:\
            « Reply #10 on: February 20, 2010, 09:35:37 AM »
            Where can quickly find more information to use VBS?

            the MS reference material can be found here.

            First it's important to know the various "dialects" of the core  Visual Basic language.

            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.

            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.

            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.

            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.

            Quote
            Again, Thanks for the extraordinary help.

            your welcome :)

            I was trying to dereference Null Pointers before it was cool.