Move multiple files from multiple folders to one folder - windows

I am looking for a .bat file that can look inside multiple folders that contain sub-folders that are named the same and move their contents to a specified folder.
Folder Structure:
Main_folder
MainTextures_folder
Props_folder
--model1_subfolder
------Textures_subfolder
----------image files
--model2_subfolder
-------Textures_subfolder
----------image files
--model3_subfolder
-------Textures_subfolder
----------image files
--model4_subfolder
-------Textures_subfolder
----------image files
I need all image files moved from their Textures_subfolder to the MainTextures_folder.
Thanks for any help.

This expects model* folders under the props folder, and that each model* folder has a textures folder. The MainTextures folder is in the Main_folder.
It's untested and should move all files from each textures folder into the MainTextures folder.
#echo off
pushd "Main_folder\Props"
for /f "delims=" %%a in ('dir model* /b /ad') do (
move /-y "%%a\textures\*.*" "..\MainTextures"
)
popd

for /r "Props_folder" %%x in (*.jpg *.png *.bmp *.whatever) move "%%~fx" "MainTextures_folder"
This code will overwrite all existing files.

Related

How do i compress multiple folders into zipped folders without creating subfolders?

I am trying to compress multiple folders (about 100) into individual zipped folders. I did this by making a .bat file like so - for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X"
My problem is that it makes a folder inside the zipped folder, but I need it to just compress the insides of the folder into a zipped folder. I can compress the content of each folder individually but that would take hours. If anybody knows how to do this I would be very grateful :)
for /D %%X in (*) do c:\Program Files\7-Zip\7z.exe"%%X.zip" ".%%X*"
pause
just needed to add .\ to to "%%X" (from "%%X" to ".%%d*")

How to copy files in specific location within multiple folders to a shared drive using windows command?

I need to copy several backup files to a shared folder
The Source to copy from looks like this below (there is other files inbetween but are not interested in copying them
C:\BackupLocation\BCK1\Logs\myLog1.log
C:\BackupLocation\BCK1\Logs\myLog2.log
C:\BackupLocation\BCK1\Logs\myLog3.log
C:\BackupLocation\BCK2\Logs\myLog1.log
C:\BackupLocation\BCK2\Logs\myLog2.log
C:\BackupLocation\BCK2\Logs\myLog3.log
C:\BackupLocation\BCK3\Logs\myLog1.log
C:\BackupLocation\BCK3\Logs\myLog2.log
I need to be able to copy any log file with the words "myLog" in the file name.
I thought about doing a For look do get the directory and then using robocopy to copy the files to my shared location
FOR /d /r %ROOT_SRC_BACKUP_LOCATION% %%G in (*logs*) DO (
Pushd %%G
Robocopy %%G "mybackup location directory" *mylog* /S
Popd )
But the problem is that the logs directory detects other logs directory... for example I have another logs directory in here
C:\BackupLocation\BCK3\server\Logs\IDontCareAboutTheLogsIntheServerDirectory.log
What is the most effective way to copy all the myLog's in the C:\BackupLocation\BCKXX\Logs\ folder?
Test this:
#echo off
Pushd "C:\BackupLocation"
for /d %%a in (bck*) do (
if exist "%%a\logs\" Robocopy "%%a\logs" "d:\mybackup location directory\%%a\logs" "*mylog*.log"
)
Popd

Create subfolder from suffix of filename then move file

I have got several image files in one folder sharing the same filename but have a different suffix
i.e:
textures\texture_suffix.dds
textures\texture_suffix1.dds
...
textures\texture_suffix10.dds
Using a batch I want to create subfolders named Texture.Suffix, Texture.Suffix2 based on the suffix of the files under textures, then move the respective file into its subfolder and rename it 'texture.dds'.
Can this be done using batch file?
Thanks for any help.
cd textures
for /f %%i in ('dir /b /s') do (
md %%~ni
move %%i %%~ni\ )
pause
write these tags in a bat file and run the bat file in the same directory that includes textures directory

To copy entire subfiles to other (only one) folder without path in windows platform

I did lots of search however i couldnt achieve what i want to do :
I have a folder which contains lots of folders and files under it. I just want to copy entire JPEG files in this folder to another folder without copying previous path tree.
I used this batch command like that :
for /r "C:\source" %%f in ("*.JPG") do #copy %%f "C:\dest" /Y
It works some files which dont contain any space in the name of files. However, it doesnt work files which contains space in file name like that :
it can find and copy "aabb.JPEG"
it can not copy "aa bb.JPEG"
any solutions?
The following works great for me
#ECHO OFF
FOR /R "c:\source" %%F IN (*.jpg) DO (
copy "%%F" "c:\dest\" /Y
)

How can I recursivly copy a directory structure and only copy the files in the bottom tier (Windows Batch)

My directory structure looks like this;
folder1
folder2 (thousands of folders like this)
folder3
someImage.jpeg
someDoc.doc
folder4 (optional folder)
someImage.jpeg
someDoc.doc
I want the script to copy the folder 2s which contain folder 4s maintaining the folder structure but only copying the files in folder 4. Like this;
folder1
folder2 (thousands of folders like this)
folder3
folder4 (optional folder)
someImage.jpeg
someDoc.doc
I've got a simple for loop which can identify the folders which contain folder 4 and then Robocopy the files to some directory. I can't figure out how to copy the entire folder structure whilst skipping the files at folder 3.
There is an option in the xcopy command that creates the directory tree.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
Do it first and then merely copy the files inside folder 4s.
as #Andryi pointed out in his comment, you can't unequivocally determine whether or not a folder is the lowest possible in the tree structure. So you must decide in advance which one you want to consider low enough to start copying. Suppose you decide it's folder fourth in the structure. In that case, use this code to get you started.
#echo off
for /d %%a in (*.*) do (
echo %%a
for /d %%b in (%%a\*.*) do (
echo %%b
for /d %%c in (%%b\*.*) do (
echo %%c
for /d %%d in (%%c\*.*) do (
echo %%d
for %%f in (%%d\*.*) do (
echo %%f
)
)
)
)
)

Resources