I have a large (aprox. 150,000) tif files, which all have the same filename. They are only unique because of the directory structure they are held in.
I would like to bulk rename the tiff files so they become unique, based on the directory structre that they are held within.
Does anyone have any method of acheiving this?
I am using Windows Server 2012 so a solution using a cmd script, batch file or windows GUI tool would be perfect.
Ideally, this is what I would like to acheieve, but if I have to have more or all of the directory structure in the final filename thsi would still be very, very helpful.
C:\A_001\B_0001\ABC\0001.tif -> ABC.tif
C:\A_001\B_0001\JKL\0001.tif -> JKL.tif
C:\A_001\B_0001\XYZ\0001.tif -> XYZ.tif
C:\A_001\B_0002\123\0001.tif -> 123.tif
C:\A_001\B_0002\456\0001.tif -> 456.tif
C:\A_001\B_0002\789\0001.tif -> 789.tif
This should work:
pushd C:\A_001\B_0002
for /d %%a in (*) do (
if exist "%%~a\0001.tif" ren "%%~a\0001.tif" "%%~a.tif"
)
popd
Which should do what you want. I've tested this and it works fine on my computer.
i made a similar foldertree on my drive F:.
Start a commandprompt from within folder "A_001"
FOR /F "TOKENS=3,4,5* DELIMS=\" %A IN ('DIR "%CD%\*.tif" /s /b /a:-d') DO MOVE "%CD%\%A\%B\%C" "%CD%\%A_%B%~xC"
Will result in:
MOVE "F:\A_001\B_0001\123\0001.tif" "F:\A_001\B_0001_123.tif"
MOVE "F:\A_001\B_0001\ABC\0001.tif" "F:\A_001\B_0001_ABC.tif"
MOVE "F:\A_001\B_0002\123\0001.tif" "F:\A_001\B_0002_123.tif"
MOVE "F:\A_001\B_0002\ABC\0001.tif" "F:\A_001\B_0002_ABC.tif"
So you'll have all your files in the folder "A_001".
Hope this helps?
#echo off
for /f "delims=" %%F in ('dir /b /s /a-d "C:\A_001\0001.tif"') do (
for %%D in ("%%~dpF.") do ren "%%F" "%%~nD%%~xF" || echo unable to rename "%%F"
)
Related
I have this schema
SOURCE
FOLDER_A
---FOLDERA1
------file1.abc
------file2.abc
------file2.txt
---FOLDERB1
------file3.abc
------file4.abc
------file.txt
I want to create a batch script which copies in a new folder only
DESTINATION
FOLDER_A1
---file1.abc
---file2.abc
FOLDERB1
---file3.abc
---file4.abc
putting in the destination only the second level (FOLDER_A should be deleted) and filtering only files with .abc extension
I wrote this code
#echo off
set SOURCE_DIR=C:\Users\%username%\Desktop\SCRIPT\source2
set DEST_DIR=C:\Users\%username%\Desktop\SCRIPT\dest
pause
setlocal enabledelayedexpansion
for /f "delims=" %%a In ('dir /ad/b %SOURCE_DIR% ') do (
set current_folder=%SOURCE_DIR%\%%a\
mkdir "dest\%%a"
for /r %SOURCE_DIR% %%f in (*.abc) do (
#copy "%%f" "dest\%%a"
)
pause
)
#pause
The problem is that in the destination I have the folder with the right name but inside of them everytime the 4 files file1.abc, file2.abc, file3.abc and file4.abc.
The goal is to have inside the first folder only file1.abc and file2.abc, and in the second folder file3.abc and file4.abc.
Where is the mistake?
Why are you using batchfiles and for-loops for this? Both xcopy and robocopy commands have exclusion features. Just type xcopy /? and robocopy /? for more information, and on the internet, you might find plenty of examples on how to do this.
Edit after first comment
It's indeed not that simple to work with the /Exclude switch, as you can see in following example:
C:\Temp_Folder\Folder_A>echo .txt>patterns.txt
// in this file, I mention that filenames, containing .txt, should not be copied
C:\Temp_Folder\Folder_A>xcopy /F /S C:\Temp_Folder\Folder_A\*.* C:\Temp_Folder\Destination\ /Exclude:C:\Temp_Folder\Folder_A\patterns.txt
// here I refer to the file, containing the patterns, not to copy
C:\Temp_Folder\Folder_A\FolderA1\file1.abc -> C:\Temp_Folder\Destination\FolderA1\file1.abc
C:\Temp_Folder\Folder_A\FolderA1\file2.abc -> C:\Temp_Folder\Destination\FolderA1\file2.abc
C:\Temp_Folder\Folder_A\FolderB1\file3.abc -> C:\Temp_Folder\Destination\FolderB1\file3.abc
C:\Temp_Folder\Folder_A\FolderB1\file4.abc -> C:\Temp_Folder\Destination\FolderB1\file4.abc
4 File(s) copied
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've written a batch script which processes a series of files, but now I want it to copy the output files to the correct directory.
for %%f in (closecaption_*.txt) do (
"%cd%\bin\captioncompiler.exe" "%cd%\%%f"
copy /y "%cd%\%%f" "Z:\Users\jbzdarkid\"
)
pause
Currently, this script will copy all of the .txt files into my home directory. However, I want it to move the .dat files (the output) into my directory instead. Ideally, it would only move the new .dat files, i.e. the ones that have just been processed.
I would like to be able to do something like this:
for %%f.txt in (closecaption_*.txt) do (
"%cd%\bin\captioncompiler.exe" "%cd%\%%f.txt"
copy /y "%cd%\%%f.dat" "Z:\Users\jbzdarkid\"
)
pause
however this does not work.
for %%f in (closecaption_*.txt) do (
"%cd%\bin\captioncompiler.exe" "%cd%\%%f"
copy /y "%cd%\%%~nf.dat" "Z:\Users\jbzdarkid\"
)
pause
should work, if my crystal ball is working correctly. It selects the name-par of %%f.
Some examples would have made the matter clearer.
The following code should work:
for /f "tokens=1,2 delims=." %%f in ('dir /a-d /b "%cd%\closecaption_*.txt"') do (
"%cd%\bin\captioncompiler.exe" "%cd%\%%f"
copy /y "%cd%\%%f.dat" "Z:\Users\jbzdarkid\"
)
pause
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)