I really need a batch file to delete the quality, sound profile, and video codec from the folder name..I was thinking a batch file that removes anything after ")" character or delete certain words from folders only.
I have 3000 movies and this would help me soooo much.
I have a bunch of folders named like this
Example:
Carnage Park (2016) 1080p 5.1 x264
Batch file result:
Carnage Park (2016)
p.s
I have searched the site but all I find is ways to rename or delete file names and not folders.
Thanks for the help guys, your the best.
To avoid errors when some matching dirs are stacked I reverse sort the dir list.
#Echo off
Cd /D "X:\start\in\folder"
For /f "delims=" %%A in (
'Dir /B/S/AD "*(*)*" ^|Sort /R'
) Do For /f "tokens=1,2 delims=()" %%B in (
"%%A"
) Do Echo Ren "%%~A" "%%B(%%C)"
If the output looks OK, remove the echo in the last line.
Sample output:
Ren "C:\Test\blah (2010) blubb" "C:\Test\blah (2010)"
Related
So I am trying to code an "A.I." through batch. The user will be able to enter in information, and the program will track keywords, and compile all data onto one text file in a specific folder. I have almost everything but a line that searches for all the filenames with a certain keyword. Here is an example. User: "Tell me EVERYTHING you know about GEORGE WASHINGTON" Program: Searches through memory for folder "George Washington" then gathers all the .txt files from that folder. It then types everything from those files to the user. Pls help, thanks :-)
you can do:
#echo off
set "foldertosearch=George Washington"
cd C:\
for /d /r %%a in ("%fodertosearch%") do (
echo found folder: %%a
cd %%a
)
for /f %%b in (*.txt) do (
echo found file: %%b
type "%%b"
)
pause
i recommend you to change the C:\ of the 3rd line to a specific folder because i am not shure the for /d loop can handle a whole drive. use the where command instead.
A very similar question to this has been asked (Put files automatically in folders) however I am struggling to convert the answer in the aforementioned question to suit my needs.
My problem is that I need to move folders into other folders using a section of their name, the question that was answered before was about moving files.
My folders have date and time stamps on them 2016-08-23 15.23.45. I need to move these folders to another folder that has just the date on them 2016-08-23.
As another small request, since I'm not very skilled with windows batch files, could someone please tell me where I will need to put my file paths into the batch file.
I need to move folders into other folders using a section of their name
My folders have date and time stamps on them 2016-08-23 15.23.45. I need to move these folders to another folder that has just the date on them 2016-08-23
Use the following batch file (test.cmd):
#echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2" %%d in ('dir /a:d /b') do (
if not exist %%d md %%d
if [%%e] neq [] move "%%d %%e" %%d >nul 2>&1
)
endlocal
Example usage:
F:\test>dir /a:d /b /s
F:\test\2016-08-23 15.23.45
F:\test\2016-08-23 15.23.46
F:\test\2016-08-23 15.23.47
F:\test\2016-08-23 15.23.48
F:\test>test
F:\test>dir /a:d /b /s
F:\test\2016-08-23
F:\test\2016-08-23\2016-08-23 15.23.45
F:\test\2016-08-23\2016-08-23 15.23.46
F:\test\2016-08-23\2016-08-23 15.23.47
F:\test\2016-08-23\2016-08-23 15.23.48
F:\test>
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
for /f - Loop command against the results of another command.
dir - Display a list of files and subfolders.
if - Conditionally perform a command.
md - Make Directory - Creates a new folder.
move - Move a file from one folder to another.
redirection - Redirection operators.
I have a lot of (50 000+) files in a folder. They are named as: "abc_012345678_abcabc.ext"
I need to create a directory for each of this file (all in one different directory), named as the "number part" (012345678) and then copy this file to this directory.
So in the end, i have 50000+ directories, called like "265415873" , "654879623" and so on and inside each directory is the filename with matching name (so in dir 265478951 is file called abc_265478951_abcabc.ext).
Big thanks for any advice!
EDIT:
I already created a simple script, that does what I need, so if anyone is interested, here it is:
#ECHO OFF
setlocal enabledelayedexpansion
FOR %%f in (*.ext) DO (
set filename=%%f
set folder=!filename:~0,-4!
set copypath=e:\work\programy\adresare_handa\adresare\!folder!
mkdir !folder!
copy !filename! !copypath!
)
pause
In this case, I only delete the extension and use the whole name of the file for the name of the directory, but I know, how to alter it, to read just the part of the file I need.
Thanx a lot again, if anyone have any comment for my version (pros/cons), please, do enlighten me :)
Bye!
#echo off
pushd "C:\some_dir"
for /f "tokens=1,2,3 delims=_" %%A in ('dir /b /s /a-d') do (
md "%%~B"
copy %%A_%%B_%%C %%B
)
only in case all files are with name pattern like "abc_012345678_abcabc.ext"
I'm relatively new to batch files. I can do VERY simple ones, however this next one is throwing me for a loop.
We have a program that generates PDF quotes for customers that saves in the following way...
FirstnameLastname_Estimate_MMDDYYYY-###
For example if I had a customer "John Doe" and we gave him an estimate (#239th in our system) on Christmas Eve this year it would look like this.
JohnDoe_Estimate_12242013-239.pdf
Right now it lives in a folder "C:\Estimates". What I'd like the batch file to do is look at all of the files in the "C:\Estimates" folder and automatically move the files sorted by year. So all of the 2012 estimates are put into a folder "C:\Estimates\2012", 2013 in "C:\Estimates\2013" etc.
Some of the batch files on here get me close, but no cigar. Any help would be great. Thanks!
Launch this in the C:\Estimates folder. Filenames should not have _ or - in the client name.
#echo off
setlocal disabledelayedexpansion
for %%a in (*.pdf) do (
for /f "tokens=3 delims=_-" %%b in ("%%a") do (
set variable=%%b
setlocal enabledelayedexpansion
set variable=!variable:~-4!
md !variable! 2>nul
move "*!variable!-*.pdf" !variable! >nul
endlocal
)
)
I am quite new to Command Prompt (Windows), however I have used it to do some file extensions changing and it is extremely helpful. I know nothing on coding, and so i am simply going off what I have read about but I am looking for a command line that I cant seem to find anywhere. I have folder, and inside that folder are 70 sub folders each labelled by a number from 1-70. Inside these subfolders are roughly 20 png picture files, that are currently numbered by a number from 1-20 in png format. I am looking for a command line to rename each file from its original name to "folder name (page number).png"
For example, I have folder called '68' and inside that folder is 1.png, 2.png, 3.png. I want the command line to change that 1.png and 2.png etc... to 68 (1).png and 68 (2). png, noticing the space between the bracket and the folder name. Sorry if i have made it confusing but I would really appreciate it and I have got some very helpful and quick answers from StackOverflow before
Thankyou if you are able to help me, as i am completely hopeless on this matter.
Only run this once - launch it from the folder containing the 70 folders.
#echo off
for /f "delims=" %%a in ('dir /ad /b') do (
pushd "%%a"
for /f "delims=" %%b in ('dir /a-d /b') do ren "%%b" "%%a (%%~nb)%%~xb"
popd
)
I am not a very experienced bash scriptor, but I guess this should do the task for you. I am assuming that you are using Linux operating system. So open a text editor and copy the following:
#!/bin/bash
NumberOfFolders=70
for((a=1; a <= NumberOfFolders ; a++))
do
cd ./$a
b=1
while [ -f $b.png ]
do
mv "$b.png" "$a($b).png"
let b=b+1
done
cd ..
done
save this script where you have you folders 1-70 (and call it whatever.ssh). Then open a terminal and write down chmod a+x whatever.ssh and after that ./whatever.ssh. This should do the job as you presented in your question.
A slight modification of the approach #foxidrive suggested, so the script can be run from anywhere and won't have to parse dir output:
#echo off
for /r "C:\root\folder" %%d in (.) do (
pushd "%%~fd"
for %%f in (*) do ren "%%~ff" "%%~nd (%%~nf)%%~xf"
popd
)
Note that this will not work in Windows XP (not sure about Windows Vista), due to a bug with the expansion of * in the inner for loop that would cause the files to be renamed multiple times.