i am trying to Unrar 400 files via batch script.
in my folder files mixed with videos
some file name is "love.blood.repack.mp4"
i have add .r for find rar file in my script
but script show with videos file like "love.blood.repack.mp4"
how to check if extension have .rar .r001 .r01 .r02 etc and then run unrar ?
only check extension not full file name
c:\unrar.bat c:\mymixedfolder
My windows .bat batch script
#echo off &setlocal
set /a nfile=0
echo Copying directory structure from %1 to %2 ...
xcopy /T "%~1" "%~2"
REM walk directory structure and convert each file in quiet mode
set "sourcefolder=%~1"
set "targetfolder=%~2"
for /R "%sourcefolder%" %%a in (*.r*) do (
echo converting "%%~nxa" ...
set "sourcefile=%%~fa"
set "sourcepath=%%~dpa"
set "targetfile=%%~na.flv"
setlocal enabledelayedexpansion
set "targetfolder=%targetfolder%!sourcepath:%sourcefolder%=!"
echo "%%~nxa"
endlocal
set /A nfile+=1
)
echo Done! Unrar %nfile% file(s)
try:
#ECHO OFF &SETLOCAL disableDelayedExpansion
SET "sourcefolder=."
FOR /R "%sourcefolder%" %%a IN (*.r*) DO (
FOR /f "delims=" %%b IN ('echo %%~xa^|findstr /r "\.r.*"') DO ECHO %%~a
)
Here is another option:
#ECHO OFF
SET "sourcefolder=."
FOR /R "%sourcefolder%" %%a IN (*.r??) DO (
if /i "%%~xa"==".rar" DO ECHO %%~a
)
Related
#echo off
setlocal EnableDelayedExpansion
set i=0
for %%a in (*.jpg) do (
set /a i+=1
ren "%%a" "!i!.new"
)
ren *.new *.jpg
I have this batch file to rename all files in folder as 1,2,3...n But the problem is its removing the caption, I want to modify it such that it will keep the caption as it is and will just add a number before a caption.
#Echo Off
SetLocal EnableDelayedExpansion
Set "i=0"
For %%A In (*.jpg) do (Set /A i+=1
Ren "%%A" "!i!%%~nA.new"
)
Ren *.new *.jpg
The filename plus extension above is %%A and the filename without extension is %%~nA. So I used Ren "%%A" "!i!%%~nA.new". Please refer to the help usage of the For command for a full explanation, enter For /? at the Command Prompt to do so.
You can separate the !i! from the %%~nA with a character of your choosing too!
I got a bunch of pictures taken with my camera in a parent folder. The filenames has this format; 'yyyymmdd_ttmmss.jpg', eg '20151008_0730.jpg'.
I want to create folders based on the 'yyyymmd'-part of the filename, but with the format 'yyyy-mm-dd'. So the file '20151008_0730.jpg' is moved into a folder named '2015-10-08'. This is what I got so far:
#ECHO OFF
SETLOCAL
SET "sourcedir=c:\temp"
PUSHD %sourcedir%
FOR /f "tokens=1*" %%a IN (
'dir /b /a-d "*_*.jpg"'
) DO (
MD %%a
MOVE "%%a %%b" .\%%a\
)
POPD
GOTO :EOF
But I don't know how to format the %%a-variable before creating the folder.
(This is a similar question asked before, but not with creating the folder on this format)
#echo off
setlocal
copy nul "%tmp%\20151008_0730.jpg"
copy nul "%tmp%\20151009_0731.jpg"
copy nul "%tmp%\20151010_0732.jpg"
set "sourcedir=%tmp%"
pushd %tmp%
for /f "delims=" %%a in ('dir /b /a-d "*_*.jpg"') do (
set "file=%%a"
setlocal enabledelayedexpansion
set "folder=!file:~0,4!-!file:~4,2!-!file:~6,2!"
echo:
rem check if folder already exist
if not exist "!folder!\nul" echo md "!folder!"
echo move "!file!" "!folder!"
endlocal
)
popd
exit /b 0
output:
md "2015-10-08"
move "20151008_0730.jpg" "2015-10-08"
md "2015-10-09"
move "20151009_0731.jpg" "2015-10-09"
md "2015-10-10"
move "20151010_0732.jpg" "2015-10-10"
You have to clean up this sample by changing sourcedir and pushd, removing echo in front of each commands, also copy nul "....".
I used here VarSubstring and delayedexpansion
After successfully removing a bunch of Google Drive Folder duplicates, some files retain a "filename(2)"name.
Is there a way to batch rename every file so the parenthesis and the number inside the parenthesis is gone?
That includes folders and sub-folders.
Try like this :
Create a file test.bat with the code below in it and replace the path to test in the var $path
#echo off
set $path="C:\Users\CN Micros\Desktop\PROGRAMMATION\test"
for /f "tokens=1-3 delims=^(^)" %%a in ('dir /b/a-d %$path%') do (
if exist %$path%\"%%a(%%b)%%c" echo ren %$path%\"%%a(%%b)%%c" "%%a%%c"
)
pause
Then run it in the CMD or by double clicking.
If the output is ok for you remove the echo
The program create 3 tokens : %%a = what's before the (), %%b What's inside the () and %%c what's after the ().
Then we arrange this 3 tokens to rename the files without the ().
If you have some file who have the same final name ie : "file(1)name", "file(2)name" --> "filename"
It will work only with the first one. If you have this case you have to add a counter at the end of file to be sure that they will be renamed.
This will create renfiles.bat.txt for you to examine in Notepad and then rename to .bat and execute if you are happy with it.
#echo off
dir /b /a-d *(*).* |find /i /v "%~nx0" |find /i /v "repl.bat" |repl "(.*)\(.*\)(\..*)" "ren \q$&\q \q$1$2\q" xa >"renfiles.bat.txt"
This uses a helper batch file called repl.bat - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place repl.bat in the same folder as the batch file or in a folder that is on the path.
Edit: This version will recurse through subdirectories:
#echo off
dir /b /s /a-d *(*).* |find /i /v "%~nx0" |find /i /v "repl.bat" |repl ".*\\(.*)\(.*\)(\..*)" "ren \q$&\q \q$1$2\q" xa >"renfiles.bat.txt"
#ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
FOR /f "delims=" %%a IN (
'dir /b /s /a-d "%sourcedir%\*" '
) DO (
SET "name=%%~na"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "newname=!name:)=!"
SET "newname=!newname:(=!"
IF "!name!" neq "!newname!" (
IF EXIST "%%~dpa!newname!%%~xa" (ECHO cannot RENAME %%a
) ELSE (ECHO(REN "%%a" "!newname!%%~xa")
)
endlocal
)
GOTO :EOF
You'd need to set your required directory into sourcedir. I used u:\sourcedir which suits my testing.
The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(REN to REN to actually rename the files.
How could i rename a certain part of all files inside a directory.
Example
[HorribleSubs] File1 [720p].mkv
[HorribleSubs] File2 [1080p].mkv
Must be renamed into
File1.mkv
File2.mkv
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
FOR /f "tokens=2delims=[]" %%a IN (
'dir /b /a-d "%sourcedir%\[*]*[*].mkv" '
) DO (
SET "newname=%%a"
ECHO(REN "%sourcedir%\[*]%%a[*].mkv" "!newname:~1,-1!.mkv"
)
GOTO :EOF
This should fix your problem.
The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(REN to REN to actually rename the files.
This is a simple batch you can use to rename a single file manually.
#echo off
title Rename Bat
echo This bat must be in the folder that
echo contains the files to be renamed.
echo Enter File Name
set /p old=
echo Enter New Name
set /p new=
ren "%old%" "%new%"
echo Done
pause
this has a loop to do multiple files manually
#echo off
title Rename Bat
echo This bat must be in the folder that
echo contains the files to be renamed.
:begin
echo Enter File Name
set /p old=
echo Enter New Name
set /p new=
ren "%old%" "%new%"
echo Done
ping -n 3 127.0.0.1 >NUL
goto begin
its real simple hope it helps. fyi it works on windows XP
place file In directory you wanna rename
#echo off
setlocal enabledelayedexpansion
dir /b ¦ find /v /c "*">filescount.txt
for /f %%f in (filescount.txt) do (
set /a "nof=%%f-2"
for /L %%n in (1 1 !nof!) do (
for %%a in (*.mkv) do (
rename "%%a" "file%%n%%~xa"
)
)
)
i want to create a dos script (.bat) to search on all sub folders and whenever it finds a file with the word MK11 in the file name it must create a folder named archive and move the file in it.
example:
c:\folder1\folder2\folderX\fileMK11.txt -> c:\folder1\folder2\folderX\archive\fileMK11.txt
c:\folder1\folder3\fMK11ile.txt -> c:\folder1\folder3\archive\fMK11ile.txt
I tried to make the following script from examples i have seen but the problem is that it creates the folder "archive" in the directory where the script is instead of the directory where the file is found.
setlocal ENABLEDELAYEDEXPANSION
set /a c=0
FOR /R %%i in (*MK11*) do (
set /a c=c+1
md archive
move "%%i" archive
)
endlocal
I think this script will get you down the road. I echoed a COPY command rather than a MOVE command, but some of the hard part is done.
#echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET TEMPFILE=%TEMP%\afinder_%RANDOM%_%RANDOM.tmp
DIR /S /B /A-D *MK11* >%TEMPFILE%
FOR /F "usebackq delims=" %%f IN (`type %TEMPFILE%`) DO (
ECHO "%%f"
FOR /F "delims=\ tokens=*" %%a IN ("%%f") DO (
SET PNAME="%%~pa"
ECHO PNAME is set to !PNAME!
ECHO "!PNAME:~-9,7!"
REM Check to see if this file is already in an Archive directory.
IF "!PNAME:~-9,7!" == "Archive" (
echo got one
) else (
echo not one
IF NOT EXIST "!PNAME!\Archive" (MKDIR "!PNAME!\Archive")
echo COPY %%f "!PNAME!\Archive"
)
)
)
IF EXIST "%TEMPFILE%" (DEL "%TEMPFILE%")
EXIT /B 0