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

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
)

Related

How to batch copy files based on a list (txt) in to another folder with same directory structure?

I have a root directory with over 25,000 files in it. These files are in loads of different subdirectories.
I also have a text file with 4300 lines in it, each line is an absolute path to one of the files in the directory. Like below,
c:\dir1\hat1.gif
c:\dir1\hat2.gif
c:\dir1\dir2\hat1.gif
c:\dir1\dir2\hat2.gif
c:\dir1\dir3\cat.zip
c:\dir1\dir3\banana.exe
I also have another root directory witch is a copy of the original root directory structure but all the directories are empty.
I would like to copy all the files listed in the text file to the directory which is empty and place all the copied files inn the respected subdirectories.
if I use the following batchfile I keep getting file overwrite prompts because it is not copying the files to the correct directories.
#echo off
set dst_folder=c:\DSTN2
for /f "tokens=*" %%i in (USEDFILES.txt) DO (
xcopy /S/E "%%i" "%dst_folder%"
)
How do I modify this so the files are copied to the correct directory?
Since you are copying specific files from a list, you need to make sure the directory structure exists in the destination if you want it in a similar folder structure. So using the power of the FOR command modifiers you can get the file path only from the file name in the file list. You will use that modifier to create the destination directory and also use it as the destination for the XCOPY command.
I have taken the liberty of providing best practices for all the code you are using.
#echo off
set "dst_folder=c:\DSTN2"
for /f "usebackq delims=" %%G in ("USEDFILES.txt") DO (
mkdir "%dst_folder%%%~pG" 2>NUL
xcopy "%%~G" "%dst_folder%%%~pG"
)

Copy files matching string(s) in a text file out of many subfolders with folder structure to another destination folder

I have a lot of image files in a folder structure like this:
/Foldername1 (hohe Auflösung)/PictureRANDOMNAME1-FB.jpg
/Foldername1 (hohe Auflösung)/PictureRANDOMNAME2-FB.jpg
[...]
/Foldername2 (hohe Auflösung)/PictureRANDOMNAME1-SW.jpg
/Foldername2 (hohe Auflösung)/PictureRANDOMNAME2-SW.jpg
[...]
/Foldername3 (hohe Auflösung)/PictureRANDOMNAME1-SP.jpg
/Foldername3 (hohe Auflösung)/PictureRANDOMNAME2-SP.jpg
[...]
Now I have a filelist.txt with a list of some of these image files, like this:
PictureRANDOMNAME1, PictureRANDOMNAME3, [...]
I would like to copy all images matching the string(s) in the text file list out of all subfolders to a new destination (not moving them) while keeping the folder structure.
Maybe I need a batch file that I just copy into the main folder with all the subfolders, together with a filelist.txt, execute it and get the same folder structure but only with the wanted files on another destination.
Special about this might be the spaces in the paths and the umlauts.
Sorry for my bad english. I honestly tried my best. Maybe some native speaker could help editing to be more understandable.
#echo off
setlocal
:: This copies the tree structure from sourcedir to destdir
xcopy /t /e sourcedir destdir
:: This reads the filenames and copies the required files
for /f "delims=" %%a in (filelist.txt) do (
for %%b in (%%a) do xcopy /s /e sourcedir\%%b* destdir
)
%%a acquires the lines from the file. Since each line is comma-separated, %%b will execute xcopy on each name on the line.
You could add >nul to the end of the xcopy lines to suppress reporting if you like.
Please note that / indicates a switch in winbatch - \ is the directory-separator.
This procedure is untested. I suggest you try it against a small dummy subdirectory tree to verify it before relying on it for your live data.

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

How to Move or Copy Folders using directory Wildcards within Batch File?

I need to set up a batch file that will copy files from a preset directory, several layers down, organized into a folder in the current directory using batch files.
The file structure looks something like this,
AAA
--0001
----textures
------file1.tga
------file2.tga
------file3.tga
--0002
----materials ...
--0003
----textures ...
--0004
----scripts ... etc
--0005 ...
--0006 ...
BBB
--0001 ... etc
---textures ... etc
CCC ...
DDD ... etc
I want to move each textures, materials, models (etc.) folders into a single folder beneath the parent item (eg. AAA) so that the folder structure then looks like this, with all sub-files in tact,
AAA
--textures
--materials
--models
--scripts
I've been trying to use a code similar to this, with no success as of yet,
for /d %%a in ('dir /b .\AAA*\textures') do copy "%%a" ".\AAA"
Whereas the wildcard would go between 'AAA' and 'textures' folders. The same would apply for every other 2nd-generation sub-folder.
I just tried another version of the command which moved the files, but not the folder. I'm launching the batch file from within the "AAA" folder.
for /d %%a in (0001) do copy "%%a" "."
I think the issue is not knowing how to properly input directory wildcards into the "for" command, which could be a very simple fix.
Any help would be greatly appreciated beyond measure.
Put this code in a .bat file, and run it inside your AAA directory
for /f "tokens=*" %%a in ('dir /b') do robocopy %%a . /s /move
for /f "tokens=*" means that all the returned values by 'dir /b' will be processed
dir \b will list the directory in bare format
robocopy is the main command, that will do the copy job.
source %%a is the variable containing the iterated subfolder name {0001\textures, 0002\materials, ...}
destination . means copy to the working directory, which is AAA in our case
option /s to search subdirectories
option /move to move instead of copy

Resources