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

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*")

Related

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

Move multiple files from multiple folders to one folder

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.

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 to delete folders but not files in a folder by cmd

How to delete folders but not files in a folder by cmd?
Such as, there is a direcory:
c:\image\1.png
c:\image\2.png
c:\image\3.png
c:\image\*.png
c:\image\folder1\*.png
c:\image\folder2\*.png
....
Now I don't know how to delete all the folders (and subfiles) folder1, folder2...", only remain the files 1.png, 2.png, 3.png, 4.png ...
for /d %F in (c:\image\*) do rd /s /q "%F"
Double up the percents if used within a batch file

batch list all .xls files in folder

I have following batch files to list all the excel files in my folder:
for /r %%i In (*.xls) DO echo %%i
However, this will also include all excel files in subfolders of my current folder. How can I prevent that? I only want the files in the folder itself, not the subfolder.
Pff, silly question, silly answer: just remove the /r

Resources