I have to write a batch script to school, which moves all .jpg files from one folder to other one and rename them at the same time. I have a problem with for loop.
set i=1
for /R %folder1% %%F in (*.jpg) do (
move "%folder1%\%%F" "%folder2%\%newname%_%i%.jpg
set /a i+=1 )
Newname is a variable entered by user.
For example if I have files named file09.jpg, fvfdfv.jpg, whatever.jpg I need to rename them to %newname%_1.jpg, %newname%_2.jpg, %newname%_3.jpg.
My problem is, that it moves all files from folder1, but in folder2 there is just one file named newname_1.jpg ... Like if all files was moved to a single one..
Do you have any tips please?
Related
I am trying to move batch files to their respective folder, they have similar names expect the batch files I want to move have "Build" on the end. For example:
Folder name: wld-vine-tstrm
Bat file name: wld-vine-tstrmBuild.bat
In the same parent directory, I also have batch files with identical names to the folder, I do not want these to move, only the ones with "Build" at the end of the file names.
setlocal enabledelayedexpansion
set folderpath=E:\Build\ModelBatches\world-wild\actor50
for %%f in (%folderpath%\*.bat) do (
set "foldername=%%~nf"
move "%%f" "!foldername:~0,-5!"
)
This is very close to the result I am looking for; it moves the "Build" batches to the respective folder, but it also removes the last 5 characters from the batches I dont want to move.
The below batch files are now missing the last 5 chars, "tstrm"
To summarize, There are two batch files for each folder in a directory, I only want to move the one ending "Build" to its folder.
You should use this:
setlocal enabledelayedexpansion
set folderpath=E:\Build\ModelBatches\world-wild\actor50
for %%f in (%folderpath%\*build.bat) do (
set "foldername=%%~nf"
move "%%f" "!foldername:~0,-5!"
)
The wildcard *build.bat finds all batch files ending with "build" but wildcard "*.bat" shows them all.
I have ~3000 folders, each with multiple files in it. Each folder contains a txt file, with a few other file types. The folder names are hashed, so right now it's a jumble of random digits. I want to rename each folder to the same name as the txt file that is inside that folder. For example:
123456/myfile.txt
Should become:
myfile/myfile.txt
The folders do not contain any subfolders, if that matters.
Any help is greatly appreciated!
for /d %%a in (*) do (
for %%b in ("%%a\*.txt") do (
ECHO ren "%%a" "%%~nb"
)
)
use a for /d to iterate over your folders and another plain for to get the filename (assuming, there is exactly one .txt file in each folder). %%~nb gets the name only without extension).
NOTE: after troubleshooting, remove the ECHO to enable the rename command.
I am new to script,
I want to copy particular files from one directory to directory.
Example:
c:\website to D:\website
C:\website contains:
flower_small.jpg
flower_large.jpg
flowerss_small.jpg
flowerss_large.jpg
I want to copy all the files ends with '_small.jpg'
I have large number of files to move.
Can you please help me??
I think you just need:
copy c:\website\*_small.jpg D:\website
However, you did say you "have large number of files to move." If you really want to move them and not have the files in both directories. Then use:
move c:\website\*_small.jpg D:\website
#echo off
setlocal
set "source_folder=c:\website"
set "destination_folder=D:\website"
pushd "%source_folder%"
for %%a in (*_small.jpg) do (
copy /y "%%a" "%destination_folder%"
)
popd
endlocal
I'm looking for a batch file that merges the content of all files in the current directory and files from all subdirectories.
Also, that would be perfect if files were separated by several new lines in the big file and probably contain the filename with filepath above the each file content.
For example, there are two files in the current folder D:\ , where our batch file is located:
1.
d:\file1.txt contains:
some
text here
hahaha
2.
d:\folderabc\file2.mp3 contains:
doremi text
I run merge.bat file on d:\ and it creates a merge file result.txt (or whatever extension) with such content:
=========d:\file1.txt=========
some
text here
hahaha
=========d:\folderabc\file2.mp3=========
doremi
I appreciate if someone share his solution for this problem.
Thank you so much.
Test this with your folder. It assumes the files are text files.
edit: This has a fix - and you can remove the "d:\base\folder" to run it from the current directory.
#echo off
for /r "d:\base\folder" %%a in (*) do (
(
echo =========%%a=========
type "%%a"
echo(
echo(
echo(
)>>"%temp%\temp.file"
)
move "%temp%\temp.file" . >nul
echo done
pause
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")