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...
Related
First of all, I am a total beginner. I was trying an ultimate script bat file solution for a game. To not annoy you with details, let me tell you what I tried to do.
Example:
I have 17 files. 10 of them are .jpg and 7 of them are .obj files.
The images are in path \mods\images and the objects are in path \mods\models.
I want to list all 17 missing files in a list.txt
The bat file will read that list, search for the files and paste them into the TTSmissing folder
and here are my problems:
The bat script only looks exactly into the source path, but not into subfolders (that's why I wrote \mods\images\, to test if it works) so
what I basically want is: \Tabletop Simulator\Mods\ as source path and
the script shall look into all subfolders, too.
The list.txt only works, when the filenames also have their extensions. is it possible to change the script so i don't need the extension? so it will only look for names and copy the files? (example: the names in the list have to be like: hello123.jpg. It's not working when its only hello123.)
How do I need to change the bat script if i don't want a list.txt but just put the list of files right into the bat file?
#echo off
mkdir %USERPROFILE%\Desktop\TTSmissing
set src_folder=%USERPROFILE%\Documents\My Games\Tabletop Simulator\Mods\Images
set dst_folder=%USERPROFILE%\Desktop\TTSmissing
set file_list=%USERPROFILE%\Desktop\list.txt
for /f "tokens=*" %%i in (%file_list%) DO (
xcopy /S/E "%src_folder%\%%i" "%dst_folder%"
)
pause
#echo off
setlocal
set "src_folder=%USERPROFILE%\Documents\My Games\Tabletop Simulator\Mods"
set "dst_folder=%USERPROFILE%\Desktop\TTSmissing"
set "file_list=%USERPROFILE%\Desktop\list.txt"
set "ext_list=.gif .jpeg .jpg .mp4 .obj .pdf .png .webm"
if not exist "%dst_folder%" md "%dst_folder%"
for /d /r "%src_folder%\" %%A in (*) do (
pushd "%%~A" && (
for /f "usebackq delims=" %%B in ("%file_list%") do (
for %%C in (%ext_list%) do (
if exist "%%~B%%~C" (
echo copy /y "%%~B%%~C" "%dst_folder%\"
)
)
)
popd
)
)
You just want to copy files so copy is easier to use than xcopy. The code will echo the copy command to test whether it is working how you want it. If satisfied, remove the echo in front of copy and run the code again to do the actual copy process.
A for /d /r loop will recursively iterate the subdirectories in %src_folder%. pushd will change the current directory to each subdirectory so as can work relative to the source files.
The for /f loop will iterate each line from %file_list%. The simple for loop will iterate each of %ext_list%. If current "name.extension" exists, it will be copied to %dst_folder%.
If you set variables names in a script, it is usually a good idea to use setlocal to keep the variables defined local to the script.
To view help for a command, use command /?. This will work for many of commands used in the code.
View command /? help for copy, for, if, setlocal ...
There is really 2 parts to this question:
I have a folder full of files that I need to temporarily move to a
new location.
However I will later need to move the files back to their original
location(s).
I have a single folder, full of files and folders that looks like this:
C:\VIDEO\My Video 1\My Video 1.mkv
C:\VIDEO\MyVideo2\MyVideo2.mkv
C:\VIDEO\My.Video.3\My.Video.3.mkv
I need to:
1. Recursively find all *.mkv files within C:\VIDEO folder
2. Output a list of the existing Dir structure/file and folder names/paths to a .txt file
3. Then Move all *.mkv files from C:\VIDEO to another folder C:\Temp
(I do not want to retain the original folder structure during this move)
At a later time I then need to:
4. Search for all *.mkv files in C:\Temp
5. Use the .txt file to help move each *.mkv file back into their original location
I guess this will probably require 2 separate batch files.
Here is my current progress:
#echo off
setlocal EnableExtensions EnableDelayedExpansion
:: Setup
set "SourcePath=C:\VIDEO"
set "DestPath=C:\Temp"
:: Output Items To Txt File
for /f "delims=\" %%A in ('dir "%SourcePath%"\*.mkv') DO echo "%SourcePath%">>"%DestPath%"\output.txt
:: Move Matching Items
for /f "tokens=*" %%a IN ('dir "%SourcePath%"\*.mkv') DO move /y "%SourcePath%\%%a" "%DestPath%"
Can somebody please help?
You want to move a tree to a flat destination (knowing you later want to move it back and have to recreate the tree)? Why on earth would one do that...
But ok:
#echo off
set "SourcePath=C:\VIDEO"
set "DestPath=C:\Temp"
echo #echo off > MoveBack.bat
for /r "%SourcePath%" %%A in (*.mkv) do (
ECHO move "%%~fA" "%DestPath%\"
>> MoveBack.bat echo move "%DestPath%\%%~nxA" "%%~dpA"
)
echo done. To move them back, execute MoveBack.bat
Instead of logging the moved files to a text file and later iterate over that file, it's easier to just build a "restore" script.
For a description of the %%~ modifiers, read the output of for /?
NOTE: I disarmed the move command for security reasons. If you are sure it works as intended, remove the ECHO.
Note: it's possible to have duplicate file names in a folder tree. This script does not account for that (saying: you may lose data in this case)
The final product:
#echo on
set "SourcePath=H:\FIXED"
set "DestPath=H:\Temp"
echo #echo on > MoveBack.bat
for /r "%SourcePath%" %%A in (*.mkv) do (
move "%%~fA" "%DestPath%\"
>> MoveBack.bat echo move "%DestPath%\%%~nxA" "%%~dpA"
)
#echo done. To move them back, execute MoveBack.bat
is now working.
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.
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)