Moving files with .bat script on windows 10 - windows

Recently I wanted to make .bat script that would move .avi files from subfolders in specified directory to another directory.
e.g.
H:\MAINDIRECTORY\dir1\avi1.avi
H:\MAINDIRECTORY\dir2\avi2.avi
H:\MAINDIRECTORY\dir3\avi3.avi
....
To one directory called e.g.
H:\Movies
I've made script which looks something like this
#echo off
move H:\Pobrane\*\*.avi H:\Filmy
But when I'm tryin to execute it I got something like this:
the file name, directory name or volume lable syntax is incorrect
Please help me find a way out from this situation.

As move does not support wild cards you can try with for /r
#echo off
for /r "H:\Pobrane\" %%# in (*.avi) do (
move /y "%%~f#" "H:\Filmy"
)

Related

Windows Batch script to rename files with it's folder name within a for loop

I have a bunch of .flv files in subdirs and I need to loop through them and rename it according to its path.
I was able to loop through them all, but I don't know how to split the path and rename it using batch script.
Here's what I have so far:
echo off
for /R %%F in (*.flv) do (
echo %%~pF
)
The "echo %%~pF" prints the path for the current file on the loop, something like this:
\folder\morefolders\activity\ NameThatIwant \Videos\
I tried spliting with "delims=\" on my for loop but I get only "echo off".
I tried other tutorials, read other questions on SO but none of them were renaming the files from a split string from the path of the file in the loop.
Could you guys help giving suggestions or direct me to any material that explains those %% codes?
Thanks.
I think you do not need to split the path, though you could do it using for /f "delims=NameInthePath tokens=1", where NameInthePath - is some word in the path and tokens= gives you the first part of the path separated by delims.
Actially, if you need to rename file name you need to use REN command. If you need to change the path for the flv file - use copy of move command.
A batch file to rename all .LOG files to .TXT in the 'demo' folder and all sub-folders:
CD C:\demo\
For /R %%G in (*.LOG) do REN "%%G" "%~nG.TXT"

Windows 7 Batch - Create subfolder, then find files with certain text in file name and move those files in the newly created subfolder

Tried my best searching for a solution but close to my need was this example which did not work. Bash: Moving multiple files into subfolders
I am not a programmer so unable to create the batch file myself for Windows 7. Any help will be appreciated.
Needed code for a batch file that does the following:-
Searches the folder for all files that have "_F1" in the file name
Creates a subfolder named as "F1" where this file is located
Move all the files searched in step 1 to the folder "F1" created in step 2
Ideally, the batch file should execute from parent folder and should complete the 3 steps in all subfolders at least till 3 levels down the parent folder.
Thanks in Advance for any help.
I tried and came up with this. Works, but is very raw. Needs to be run manually from inside of each folder (100's of them)
MKDIR F1
MKDIR F2
DO 500
move *_F1*.* F1
move *_F2*.* F2
ENDDO
Try like this :
#echo off
for /f "delims=" %%a in ('dir /s/b/a-d *.* ^| find /i "_F1"') do (
if not exist "%%~dpaF1" md "%%~dpaF1"
move "%%~fa" "%%~dpaF1")

Bulk renaming files in relation to the folder names

I am very new to coding and bulk processes but i am looking for a command line SPECIFICALLY for windows command prompt and i am wondering if such a thing exists. So I have a folder containing 111 subfolders, with each subfolder containing between 20 and 40 png image files. Each subfolder is named 001-111 accordingly and the png files are ordered how i want them, however i am looking for a command line that would be able to quickly and efficiently name all the pngs in the folders to the name of the folder followed by the png number in brackets
e.g. for folder 037, i would want the png's to be renamed to: 037(1), 037(2), 037(3) etc...
I am hoping for the best although i am unsure such a code may not be possible or be simply done.
Also if you come up with a code that achieves this process, it would be great if you could reply with the simple command line that i could use rather than a full explanation because i am new to coding and far from fluent with the language or terms or how things work. I know this same process can be achieved by going select all>rename (ctrl a>f2) and renaming to the folder name however i need to use this process frequently and dont want to have to open each folder, i would rather have a command line for cmd that would do it swiftly
Thank you and a simple answer would be greatly appreciated
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "parentdir=u:\parent"
FOR /l %%a IN (1001,1,1111) DO (
SET dir=%%a&SET "dir=!dir:~1!"
FOR /f "delims=" %%i IN ('dir /a-d /b "%parentdir%\!dir!\*.png" 2^>nul') DO (
ECHO REN "%parentdir%\!dir!\%%~nxi" "!dir!(%%~ni)%%~xi"
)
)
GOTO :EOF
Test results:
Starting directory :
u:\parent\001\1.png
u:\parent\037\1.png
u:\parent\037\2.png
u:\parent\111\999 with spaces in name.png
Script response
REN "u:\parent\001\1.png" "001(1).png"
REN "u:\parent\037\1.png" "037(1).png"
REN "u:\parent\037\2.png" "037(2).png"
REN "u:\parent\111\999 with spaces in name.png" "111(999 with spaces in name).png"
Obviously, you'd need to replace the value assigned to parentdir with your actual target directory name.
The script will report the renames it proposes to do. To actually invoke the rename remove the ECHO keyword.
I would create a batch file like so:
renamepng.bat:
cd %%1
if ERRORLEVEL 1 goto end
for %f in *.png do mv "%f" "%%1(%f).png"
cd ..
:end
This will attempt to cd to the directory name provided on the command line, abort if that fails, then rename all the .png files and return to the previous directory
then call it like so:
for %d in ??? do call renamepng.bat %d
which will loop through all 3-character file and directory names in the current directory, can call the batch file on each one. Using call instead of just the batch file name causes execution to return to the loop when the batch finishes.

Want to execute command on each file in directory one at a time through batch file windows

I am currently doing this to execute a single command on a particular type of files in directory.
COPY *.prn /B \\\\{$PC}\\{$PRINTER}
The PC And Printer Part is redundant no need to understand that
Instead of executing all files at once I want to be able to do one file at a time through a loop
try this:
for %%i in (*.prn) do COPY "%%~i" /B \\\\{$PC}\\{$PRINTER}
Im not entirely sure what you mean but try this, it will execute the command once for each file in the current directory and (all subdirectories, but this exact snipets not ideal for subdirectories) ending with the extension .prn:
for /r %%a in (*) do (
if %%~xa == .prn (
copy %%~na%%~xa /B \\\\{$PC}\\{$PRINTER}
)
)
Tell me if this doesn't work or you want to do this for subdirectories as well.
Yours, Mona

Batch script to rename and move files

I have a radio management system which is capable of running batch scripts after shows.
I'm looking for a batch script file that renames any file in the directory like so:
1.mp3 --> [Replay]1.mp3
And then move the file from folder a to folder b.
Any thoughts on how do i go about creating such script in a syntax level?
Here you go
ren *.mp3 [Replay]*.*
There are many ways to do what you request, this script does that by searching all mp3 files in the current folder and move them to folderb specifying a new name.
#ECHO off
FOR %%i IN (*.mp3) DO (
MOVE "%%i" "folderb\[Replay]%%i"
)

Resources