I have a lot of movies in different genre folders. What I want to do through a batch file is create a folder for each movie in the same genre folder as where the movie is. For example:
/Movies/SciFi/
/Movies/SciFi/the matrix.avi
/Movies/SciFi/the matrix reloaded.mkv
/Movies/Comedy/
/Movies/Comedy/borat.avi
/Movies/Comedy/dinner for schmucks.avi
Basically I want to run a batch file from the parent folder Movies, scan for all *.mkv *.avi *.mp4 files in the genre folders and create folders based on the movie names. The name of the folders should be:
.(moviename without extension).backdrop
Ofcourse the folder shouldn't be created if it already exists. This is what I have so far:
for /f %%f in ('dir *.avi *.mkv *.mp4 /b') do md .%%~nf.backdrop
This has some disadvantages though: I have to run it from within each genre folder and if a file-name has a space in it, this command will only catch everything up till the space, rendering the aboce command pretty much useless.
Hopefully you guys can help me out.
No need for the /r option if you don't want to walk a hierarchy. Also, a simple if statement can avoid trying to create an already existing folder
for /D %%D in (\Movies\*) do for %%F in ("%%~D\*.avi" "%%~D\*.mkv" "%%~D\*.mp4") do (
if not exist "%%~D\%%~nF.backdrop" md "%%~D\%%~nF.backdrop"
)
Quotes will handle the spaces;
#echo off
for /r "c:\movies\" %%d in (.) do (
pushd %%d
echo now in %%d
for %%f in (*.avi *.mkv *.mp4) do (
md "%%~nf.backdrop"
)
popd
)
This should create SOMEMOVIE.backdrop in the Category\SOMEMOVE\ dir.
If you want them in the root just md "..\%%~nf.backdrop"
(This assumes there are no other subdirs in the movie dir as its recursive so would include them)
Related
I would like to append my folder name to all the available .txt files inside a subfolder. Below is the file/directory structure. I need to achieve this in Windows BATCH script.
C:\Source\Source1\1\a.txt C:\Source\Source1\1\b.txt
C:\Source\Source1\2\a.txt C:\Source\Source1\2\b.txt
C:\Source\Source2\3\a.txt C:\Source\Source2\3\b.txt
The above files should be renamed like below:
C:\Source\Source1\1\1_a.txt C:\Source\Source1\1\1_b.txt
C:\Source\Source1\2\2_a.txt C:\Source\Source1\2\2_b.txt
C:\Source\Source2\3\3_a.txt C:\Source\Source2\3\3_b.txt
Similary, I have Source1...Source30 and under each source directory, I will have multiple folders with different numbers. I need to rename all the files under these directories and append the number(directory name) to the file name.
So far below is what I wrote:
for %%* in (.) do set CurrDirName=%%~nx*
echo %CurrDirName%
for /r %%x in (*.txt) do ren "%%x" "%CurrDirName%_%%x"
With this, I am able to achieve it in a single directory. I couldn't make it recursive. Could you guys please help me with this.
#echo OFF
SETLOCAL EnableExtensions
for /F "delims=" %%G in ('dir /B /S "C:\Source\*.txt"') do (
for %%g in ("%%~dpG.") do ECHO rename "%%~fG" "%%~nxg_%%~nxG"
)
pause
where the FOR loops are:
outer %%G loop creates a static list of .txt files (recursively), and
inner %%g loop gets the parent folder of every particular file.
The rename command is merely displayed using ECHO for debugging purposes. To make it operational, remove word ECHO (no sooner than debugged).
Moreover, I'd consider checking whether a particular file is already renamed…
I have lots of folders including images in it. Example:
C:\U2090_08
C:\U2111_08
C:\U2024_03
C:\U2024_08
C:\U2049_15
C:\U2049_35
There are 3-4 jpg files in every folder. I want to create a sub-folder called "kck" in every folder and move jpg files to this subfolder.
Example:
Before process:
C:\U2049_35\1.jpg
C:\U2049_35\2.jpg
C:\U2049_35\3.jpg
After process:
C:\U2049_35\kck\1.jpg
C:\U2049_35\kck\2.jpg
C:\U2049_35\kck\3.jpg
Here is what I am trying:
#echo off
cd %USERPROFILE%\Desktop
:: Sorting images in '\Desktop\images'
for /f "delims=" %%I in (' dir /b "%USERPROFILE%\Desktop\images\*.jpg" ') do (
if not exist "%USERPROFILE%\Desktop\images\%%~nI\kck" ( md "%USERPROFILE%\Desktop\images\%%~nI\kck" )
move "%USERPROFILE%\Desktop\images\%%~I" "%USERPROFILE%\Desktop\images\%%~nI\kck\"
)
exit
Folders including jpg files in a folder called images on desktop.
Any ideas ?
Advanced Renamer software is able to do this. I have just tried it and it have very good move options. It solved my problem.
Next code snippet could help:
#echo off
pushd "%USERPROFILE%\Desktop\images"
:: Sorting images in '\Desktop\images' (subfolders only)
for /f "delims=" %%I in (' dir /b /A:D ') do (
if exist "%%~nxI\*.jpg" (
md "%%~nxI\kck" 2>NUL
move "%%~nxI\*.jpg" "%%~nxI\kck\"
)
)
popd
exit
all paths used in dir, md and move commands are relative to the current directory which is changed to "%USERPROFILE%\Desktop\images" via the pushd command;
note 2>NUL: redirected STDERR stream in the md "%%~nxI\kck" 2>NUL command instead of testing created folder existence explicitly by if not exist "%%~nxI\kck\NUL" md "%%~nxI\kck".
I have n number of Sub-folders with images. I want to move all the images to Main Folder for organize them correctly.
For Example -
C:\Users\HP\Downloads\NeoDownloader\Book Cover\fc02.deviantart.net\fs17\i\2007\225\9\0\front_cover_of_myths_book_by_cathydelanssay.jpg
C:\Users\HP\Downloads\NeoDownloader\Book Cover\fc02.deviantart.net\fs30\i\2008\092\8\7\The_Seagull_by_rei_i.jpg
Like the above location, I have more then 2000 image. I want to move all those images in one main Folder.
If the folders names are constant I can Write Batch File. But Those sub-folders are not the same. So I can't specify in the batch file. Its difficult to move without Coding. So help me to organize the Images in My Computer.
Notes -
All images are jpg format only
List item last folder contain only few of
images, other subfolders not have image file.
#echo off
setlocal enableextensions
set "inputFolder=C:\Users\HP\Downloads\NeoDownloader"
set "outputFolder=c:\somewhere"
for /r "%inputFolder%" %%a in (*.jpg) do (
if not exist "%outputFolder%\%%~nxa" (
move "%%~fa" "%outputFolder%"
) else (
for /f "delims=" %%b in ('dir /b "%outputFolder%\%%~na_~[*]%%~xa" 2^>nul ^| find /c /v ""') do (
move "%%~fa" "%outputFolder%\%%~na_~[%%b]%%~xa"
)
)
)
Do a recursive enumeration of the files. For each file found, if it does not exist in target folder, move to target. If there is a file with the same name, it is moved with an incremental file name. Not bulletproof but should do the work.
Make sure you create the output directory before running the batch. I learned this the hard way...
I'm trying to tidy up a data folder and have written a batch file to take care of a lot of preliminary work (delete empty folders, delete junk files, etc), but I'm falling over when trying to deal with files within duplicate folders.
This is an example of the current situation:
w:\Data\Corporations\555\20130101\Concat_000001\555_20130101_data.zip
w:\Data\Corporations\555\20130101\Concat_000002\555_20130101_data.zip
w:\Data\Corporations\555\20130101\Concat_000003\555_20130101_data.zip
w:\Data\Corporations\555\20130101\Concat_000004\555_20130101_data.zip
There should only be one Concat folder per YYYYMMDD folder, and should look like this:
w:\Data\Corporations\555\20130101\Concat\555_20130101_data.zip
There are hundreds of folders in w:\Data\Corporations to be processed, so I figure I need to first of all find any folder named Concat_*, make a folder named Concat within the same parent folder, and then move any zip from Concat_ to Concat.
I have tried various combinations of FOR /D in (Concat_*) with MD and MOVE commands, but with no luck so far. I've also tried calling a subroutine from the FOR statement that would jump back a level in the tree, create a folder named Concat, go back to Concat_* and move the .zip files, but again with no luck.
Any help would be greatly appreciated.
Cheers,
Pete
try this:
for /r "w:\Data\Corporations\555" %%a in (*.zip) do for %%b in ("%%~dpa.") do md "%%~dpbConcat" 2>nul & move /y "%%~fa" "%%~dpbConcat"
The following does what you asked. If you uncomment the last line, then empty config_* folders will be removed. Non-empty config_* folders will be preserved.
#echo off
for /f "delims=" %%F in ('dir /b /ad /s concat_*') do (
if not exist "%%~dpFconcat\" mkdir "%%~dpFconcat\"
if exist "%%F\*.zip" move /y "%%F\*.zip" "%%~dpFconcat\" >nul
REM uncomment line below if you want to remove empty concat_* folders
REM dir /b "%%F"|findstr "^" >nul || rd "%%F"
)
I am trying to find a way to create a Windows batch script that will look at a target folder full of .pdf files and move (or copy) them to another directory with existing subfolders based on the filename.
The files and folders are names of actual people. I want to be able to get that person's pdf into their existing folder using a script.
Say I have 2 files in my folder; smithJohn015.pdf and thomasBill030.pdf.
I would like to be able to put smithJohn015.pdf into folder SmithJohn and thomasBill030.pdf into folder ThomasBill.
I don't want the script to create new folders or overwrite existing files if there's a duplicate filename.
I'm not necessarily looking for anyone to write a script for me, but if anyone can just get me started in the right direction it would be appreciated.
Try modifying this answer for your evil purposes.
#echo off
setlocal
pushd "c:\path\to\PDFs"
for /d %%I in (c:\Path\To\People\*) do (
for %%F in (*) do (
for /f %%A in ('echo %%~nF ^| find /i "%%~nI"') do (
set /p a="Moving %%F to %%I... "<NUL
move "%%F" "%%I" >NUL
echo Done.
)
)
)
popd
You'll need to add a check for if not exist pdffile before the move, but there's a starting direction for you anyway.
The following assumes the target subfolders' location contains only the subfolders where the PDFs may go and that every PDF that you want to move has a name formatted as the corresponding subfolder's name followed by exactly three characters (same as in your examples):
#ECHO OFF
FOR /D %%D IN ("D:\path\to\subfolders\*") DO (
MOVE "D:\path\to\PDFs\%%~nD???.pdf" "%%D"
)
Or as a one-liner to execute directly at the command prompt:
FOR /D %D IN ("D:\path\to\subfolders\*") DO (MOVE "D:\path\to\PDFs\%~nD???.pdf" "%D")
folderlist.txt contains all names of folders in which you want to copy respective PDFs.
xcopy is copy command. format xcopy "source" "destination" /parameters.
pause is just to keep command window on
for /F "tokens=*" %%A in (folderlist.txt) do (
xcopy "E:\path\to\source folder\<prefix>%%A<suffix>.pdf" "E:\path\to\destination folder\<prefix>%%A<suffix>\" /s)
pause
You can use wildcards in source & destination paths.