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

Author Topic: need batch file to remove file extensions in current directory and subfolders  (Read 5891 times)

0 Members and 1 Guest are viewing this topic.

mario21lv

    Topic Starter


    Rookie

    Thanked: 4
    i have made a batch file that can be run in the current directory its in to remove .vir file extensions in that folder. i need the batch file to also remove the .vir extensions in subfolders. please help.

    for /f "delims==" %%F in ('dir  /b /s  *.vir') do ren "%%~nxF" "%%~nF"

    i have added /s but i have had no luck.



    BillRichardson



      Intermediate

      Thanked: 15

      for /f "delims==" %%F in ('dir  /b /s  *.vir') do ren "%%~nxF" "%%~nF"

      rem Test with:

      for /f "delims==" %%F in ('dir  /b /s  *.vir') do echo %%F

      rem and then

      for /f "delims==" %%F in ('dir  /b /s  *.vir') do copy "%%~nxF" "%%~nF"

      rem  ren  might misfire  when two folders are involved for source and 
      rem destination

      rem do a:  ren /?

      rem if the copy works, then del source file



      Bill Richardson

      BillRichardson



        Intermediate

        Thanked: 15
        File Extension VIR
        File type: Virus Infected File
        Click here to run a free instant scan for VIR related errors.Notes about the VIR file extension:
        Errors in your registry are one of the common causes for incorrect file associations on your windows system. It is highly recommended that you check your registry for file association errors (will also check for any other registry errors).


        The VIR file type is primarily associated with 'Virus Infected File'. Renamed by Symantec Anti-Virus.


        Cannot access VIR files on windows?
        When windows gives you an error message saying that it
        "Cannot open VIR files", this means either:

        A. You need to identify a program that can open the file
        B. Or your registry may be damaged


        RECOMMENDED:
        In both cases it is strongly recommended that you clean registry
        Bill Richardson

        mario21lv

          Topic Starter


          Rookie

          Thanked: 4
          File Extension VIR
          File type: Virus Infected File


          i know what .vir is. these were put in the quarantine folder when running a beta virus removal. it read the wrong files and added .vir to the end.

          mario21lv

            Topic Starter


            Rookie

            Thanked: 4
            rem Test with:

            for /f "delims==" %%F in ('dir  /b /s  *.vir') do echo %%F

            rem and then

            for /f "delims==" %%F in ('dir  /b /s  *.vir') do copy "%%~nxF" "%%~nF"

            rem  ren  might misfire  when two folders are involved for source and 
            rem destination

            rem do a:  ren /?

            rem if the copy works, then del source file






            sorry, but i really dont know anything about batch files. i managed to put this together from reading forums. the only test i have written is the one u see.


            for /f "delims==" %%F in ('dir  /b /s  *.vir') do echo %%F
            for /f "delims==" %%F in ('dir  /b /s  *.vir') do copy "%%~nxF" "%%~nF"

            is this the only text that is needed in the batch file or am i missing something

            update: well the second line of code worked. but it still only changed the file extensions in the current folder the .bat file was in and not the included subfolders. so its basically my original code but it now makes a copy with the .vir gone.
            « Last Edit: January 26, 2010, 12:51:35 AM by mario21lv »

            Helpmeh



              Guru
            • Roar.
            • Thanked: 122
              • Yes
              • Yes
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 8
            For /f "tokens=1,2 delims=." %%a in ('dir /b /s FOLDER\*.vir') do (
            copy "%%a.%%b" "%%a"
            rem del "%%a.%%b"
            )

            If it successfully creates new files without extensions, then remove the REM and it will delete the original file.
            Where's MagicSpeed?
            Quote from: 'matt'
            He's playing a game called IRL. Great graphics, *censored* gameplay.

            mario21lv

              Topic Starter


              Rookie

              Thanked: 4
              For /f "tokens=1,2 delims=." %%a in ('dir /b /s FOLDER\*.vir') do (
              copy "%%a.%%b" "%%a"
              rem del "%%a.%%b"
              )

              If it successfully creates new files without extensions, then remove the REM and it will delete the original file.


              your code did not work at all. i wanted to see what was happening with my first line so i put a Pause on the batch file. after running i noticed the it was actually finding my files but it was not removing the .vir extension.



              for /f "delims==" %%F in ('dir /b/s *.vir') do ren "%%~nxF" "%%~nF"

              ECHO.Haulting Batch
              PAUSE>NUL
              GOTO EOF

              the error it came up with was "system cannot find the file specified"
              below is a zip file containing a paint file the i just added .vir to the end. the batchfile is inside and once run u can have a better idea of what i mean.
              http://www.box.net/shared/zm81c6t6v4

              Salmon Trout



                Genius

                Thanked: 755
                • Yes
              • Computer: Specs
              • Experience: Experienced
              • OS: Windows 7
              You are not feeding the right parameters to REN. I have posted this twice in the last few days, I suppose one more time will not hurt.

              Open a command window. Type REN /? and press Enter. Read the help. You should know this already!!!

              Code: [Select]
              C:\>ren /?
              Renames a file or files.

              RENAME [drive:][path]filename1 filename2.
              REN [drive:][path]filename1 filename2.

              Note that you cannot specify a new drive or path for your destination file.

              The last line means that the destination file (new name) must be not a full path, just a name(and extension if desired)

              If you want you can omit the [drive:path] part for files which are IN THE CURRENT FOLDER.

              But NOT for for files which are NOT in the current folder, for example below it in subdirs.

              In your code above you are doing dir /b /s so you are getting a list of full paths for files in the current folder and any subfolders. Then you are doing ~nx (why?) which strips off the drive:path bit and leaves just the filename and extension. So the files which are not in the current folder are (of course) not found.



               

              Stirb nicht vor mir - Rammstein

              JenniC



                Rookie

                Quote
                i have made a batch file that can be run in the current directory its in to remove .vir file extensions in that folder. i need the batch file to also remove the .vir extensions in subfolders. please help.

                Try this biterscripting script.


                Code: [Select]
                # Script DeleteVir.txt
                var str list, file
                lf -r -n "*.vir" "." > $list
                while ($list <>> "")
                do
                    lex "1" $file
                    system delete ("\""+$file+"\"")
                done



                See the help page for the -r (recursive -  search subfolders) flag here - http://www.biterscripting.com/helppages/lf.html .




                Grimbear13



                  Rookie

                  I haven't tried the -r in if's but I have tried the /r in a for loop and it doesn't seem to search through subdirectories correctly.

                  JenniC



                    Rookie


                    "lf -r" command will correctly search thru subdirectories. Try this one command in biterscripting.

                    Code: [Select]
                    lf -r -n "*.vir" "C:/somefolder"

                    It will show you all "*.vir" files in all subdirectories (at all levels) within "C:/somefolder".