Extracting files out of a huge directory - windows

I have a folder that is filled with:
.mp3 files
Folders that contain mp3 files Folders that contain some
amount of folders.
Each sub-directory may or may not have mp3 files.
I need to extract only the mp3 files out of it and save them elsewhere. The problem is that 90% of the mp3 files have spaces in them. So running this particular script does not work:
pushd C:\Users\XXX\Desktop\UNSORTED_MUSIC
for /r %%a in (*.mp3) do copy %%a C:\Users\XXX\Desktop\YEAH\"%%~nxa" /y
It moves space-less files just fine. But otherwise, it skips the rest. How can I modify my script to work?

for /r %%a in (*.mp3) do copy "%%a" C:\Users\XXX\Desktop\YEAH\"%%~nxa" /y
Simply quote any string that may contain separators like spaces.

Related

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 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

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
)

Windows batch copy files from subfolders to one folder

I had tried to make batch script that copies all *.tif files located in D:\images(random named subfolders here) to d:\all.
xcopy D:\Downloads\*.TIF D:\temp\ /s
works, but it copies with all folder tree. I tried to use other keys, but its dont works.
Thanks for help!
FOR is your friend. Read HELP FOR on the /R option and the %~nx variable substitution; and then try this very simple code.
pushd d:\downloads
for /r %%a in (*.tif) do (
echo COPY "%%a" "d:\temp\%%~nxa"
)
popd
watch carefully the results and then remove the ECHO command.
You will have to refine the code to cope with errors, duplicate names, edge cases, names with reserved characters, race conditions, cosmic events...
Searched files using windows file explorer for e.g. *.gif , I got files in search window, used Edit=>Select All , copy and then pasted to desired folder. This copied all the gif files in all sub directories to single folder.
For large number of files, it sometimes hangs/not responding, but otherwise works ok.
pushd D:\Source
for /r %%a in (*.?*) do (
MOVE "%%a" "D:\Destination folder\%%~nxa"
)
popd
You can also use the XXCOPY freeware. Works like XCOPY, but when you use a /SG parameter, it flattens the sub-directories. See how to use it here.

Batch script to pngcrush all files in all subfolders

I have a folder structure with one main parent folder containing many subfolders, and in these some PNGs, something like:
.../data
.../data/013523/
.../data/345343/
.../data/395338/
.../data/013523/filex.png
.../data/013523/filey.png
.../data/345343/filea.png
.../data/345343/fileb.png
.../data/345343/filec.png
I'd like to crush all these PNGs with a Windows batch-script knowing only the location of the parent data folder (ie the folder names and png names are unknown, it should just crush all PNGs in all folders).
I took a look at Drag and drop batch file for multiple files? but this didn't seem to be quite what I was after.
Oh and no fancy naming options required, crushing in-place is fine.
Well
for /r ...\data %%x in (*.png) do pngcrush "%%x"
should do it.
If the path to your data directory contains spaces somewhere, the following should work better, though:
pushd "...\data"
for /r %%x in (*.png) do pngcrush "%%x"
popd

Resources