Computer Hope

Microsoft => Microsoft DOS => Topic started by: mario21lv on January 25, 2010, 11:31:47 PM

Title: need batch file to remove file extensions in current directory and subfolders
Post by: mario21lv on January 25, 2010, 11:31:47 PM
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.


Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: BillRichardson on January 25, 2010, 11:56:41 PM

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



Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: BillRichardson on January 26, 2010, 12:06:05 AM
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
Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: mario21lv on January 26, 2010, 12:35:13 AM
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.
Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: mario21lv on January 26, 2010, 12:39:22 AM
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.
Title: Re: need batch file to remove file extensions in current directory and subfolder
Post by: Helpmeh on January 26, 2010, 04:58:23 AM
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.
Title: Re: need batch file to remove file extensions in current directory and subfolder
Post by: mario21lv on January 26, 2010, 11:06:48 AM
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
Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: Salmon Trout on January 26, 2010, 12:47:08 PM
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.



 
Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: JenniC on February 14, 2010, 01:00:09 PM
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 .



Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: Grimbear13 on February 15, 2010, 01:06:55 PM
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.
Title: Re: need batch file to remove file extensions in current directory and subfolders
Post by: JenniC on February 18, 2010, 09:21:23 AM

"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".