I am trying to delete file from a folder which has 3,500 + files.
FolderA(3,500+Files), FolderB(<260 Files).
What I want is that I want a FolderA(3,500+Files) - FolderA(list.txt) = Missing files.
I have tried :
Get-Content c:\path\to\list.txt | Remove-Item
It doesn't work.
FolderA has over 3,500 files and within the folder i have a file called "list.txt" which has list of all files which I would like to delete from FolderA
Hope this make sense.
Thanks,
Yogs
cd "C:\Users\gggggg\Desktop\missing2"
Get-Content "C:\Users\XXXXX\Desktop\missing2\ToBeDeleted.txt" | Remove-Item
Change active folder to the folder to be processed, get the list and remove each item
For a batch solution
for /f "delims=" %%a in ("C:\Users\XXXXX\Desktop\missing2\ToBeDeleted.txt") do (
del "C:\Users\gggggg\Desktop\missing2\%%a"
)
dir /b /a-d "FolderA*"|findstr /g:"FolderA\list.txt"
should do what you appear to want.
What has "FolderB" go to do with the problem?
--- er, you want to delete files that are not in the list list.txt ?
Well, the above should give you a list of files-to-be-deleted, so
for /f "delims=" %%a in ('dir /b /a-d "FolderA*"^|findstr /g:"FolderA\list.txt"') do ECHO(del "FolderA\%%a"
should echo the same list. If it is correct, change the echo(delto del after verification to actually delete the files.
Related
Ok, I'm total new at this... Basically I'm using a tool call mkvmerge to attach multiple font files(.ttf) to .mkv files. I have separated the .mkv files into folders together with the respective fonts I would like to attach.
My aim is to create a batch that creates a copy of all the .mkv files with all the added attachments and deposits them in a newly created a folder (i.e Revised) in the parent directory.
Beginning with just a single folder:
mkdir Revised
for %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "%%~.ttf"
This works if I change the "%%~.ttf" to an actual .tff file name
(i.e
mkdir Revised
for %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "sans serif.ttf"
and I would end up with newly created Revised folder which contains a .mkv file with the sans serif.tff file attach within the .mkv file itself.
However I would like to add multiple .ttf files without naming them individually. (searching online it seems I need something like "$file" though I dont know how to use it)
Next if I have a parent folder with multiple sub-folders:
mkdir Revised
for /R %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "%%~.ttf"
This just flat out doesn't work. Not just because of the "%%~.ttf" issue I'm sure.
I know that it might be a bit too ambitious, so if some one could just help solve the first half of my problem, that would be lovely. Thanks a lot in advance.
Ps: If anyone need to understand the mkvmerge specific commands to help out: https://mkvtoolnix.download/doc/mkvmerge.html
Updates: For the first part
mkdir Revised
for %%x in (*.ttf) do (
for %%A in (*.mkv) do "%mkvmerge%" -q -o "Revised\%%A" "%%A" --attachment-mime-type application/x-truetype-font --attach-file "%%x"
)
It seems to work better but I think the script would now add and remove the the .ttf files until the last .ttf file in the folder remained.
Please give this a try. (Remember to set your %mkvmerge% variable to your executable path):
#echo off
set "mkvmerge=C:\Some Path\mkvmerge.exe"
for %%a in (*.ttf) do (
for /f %%i in ('dir /s /b /a-d *.mkv ^| findstr /vi Revised') do (
if not exist "%%~dpiRevised" mkdir "%%~dpi\Revised"
if not exist "%%~dpiRevised\%%~nxi" copy "%%~fi" "%%~dpiRevised"
"%mkvmerge%" -q -o "%%~dpiRevised\%%~ni_rev%%~xi" "%%~dpiRevised\%%~nxi" --attachment-mime-type application/x-truetype-font --attach-file "%%~dpi%%a"
)
)
So to explain what went wrong with your examples:
In the for loop, you take apply from the mkv inside the root folder, and apply a ttf file to it and create the new mkv file with the attached ttf to the Revised directory, then for the next ttf you again copy from the root directory, overwriting the mkv file in the Revised directory with a new one where a new ttf was applied etc.
Instead, we need to first make a copy of the mkv file into the Revised directory then we apply the first ttf file to itself in Revised and then take the mkv with the already attached ttf and apply another ttf to it until all ttf files have been applied to the new mkv inside of Revised The original mkv and all the ttf files will remain in the parent folder.
Note if any of what I explained does not make sense, let me know and I will rephrase.
I have decided to take a stab at this, it is intended to be run from the parent directory holding your directories, (I have assumed that those directories are all on the same level, this is not recursing through nested directories).
Please be aware that I am unable to test this.
#Echo Off
Set "mkvm=%UserProfile%\Downloads\Video Players, Editors, & Downloaders\MKVTool Batch Modifier\mkvmerge.exe"
For /F Delims^=^ EOL^= %%A In ('Dir/B/AD 2^>Nul^|FindStr/IVXC:"Revised"'
) Do If Exist "%%A\*.mkv" (If Exist "%%A\*.ttf" (
If Not Exist "Revised\" MD "Revised" 2>Nul||Exit /B
Call :S1 "%%A"))
GoTo :EOF
:S1
PushD %1 2>Nul||Exit /B
Set "as=--attachment-mime-type application/x-truetype-font --attach-file"
Set "ttfs="
For /F Delims^=^ EOL^= %%A In ('Where .:*.ttf'
) Do Call Set "ttfs=%%ttfs%% %as% "%%~nxA""
For /F Delims^=^ EOL^= %%A In ('Where .:*.mkv'
) Do "%mkvm%" -q -o "%~dp0Revised\%%~nxA" "%%~nxA" %ttfs%
PopD
I think I have also made this in such a way as to allow for more than one .mkv file in a directory, where each will be attached to all of the same .ttf files.
Get-ChildItem *.mkv | ForEach-Object {
$FontFlags = ""
Get-ChildItem -LiteralPath $_.BaseName -Exclude *.xml | ForEach-Object {
$FontFlags += " --add-attachment `"$($_.FullName)`""
}
Write-Host "Running &`"C:\Program Files\MKVToolNix\mkvpropedit.exe`" `"$_`" $FontFlags"
Invoke-Expression "&`"C:\Program Files\MKVToolNix\mkvpropedit.exe`" `"$_`" $FontFlags"
}
Read-Host "Press any key to exit..."
Make a folder with the same names as mkv without extension. Put mkv file, folder , this code in same folder and run it.
I didn't make this code. I asked someone to make this for my personal use.
I'm running xcopy within a Jenkins build.
I have the following directory structure:
Ensure\
a
Web_ERP
b
c
Web_ERP
Web_ERP
Web_ERP_Claims
Web_ERP_Finance
I'm trying to copy all folders which start with "Web_ER*" under Ensure (depth=1) to my current workspace.
node () {
stage ('Setup') {
deleteDir()
bat '''
IF NOT EXIST c:\\deploy mkdir c:\\deploy
cd ..\\Ensure
xcopy Web_ER* "%WORKSPACE%" /e
'''
}
}
In reality, all the folders which start with Web_ER* are being copied along with Web_ER* folders which reside under folders a and c.
I want only Web_ER* folders which reside under Ensure to be copied along with their content.
I've tried the following switches with xcopy: /i /e /s /m but I get the same result every time.
Edit #1:
#magoo when I run the command you gave it copies all the files which are under each one of the Web_ER* folders without the folders themselves, I want to copy all the folders strating with "Web_ER*" with all their subdirectories to my destination folder.
Following your example I've also tried:
for /f "delims=" %%a in ('dir /b /ad web_er*') do xcopy ".\\%%a" "%WORKSPACE%" /e /y
But to no avail.
In linux for example it's as easy as:
cp -R folder/pattern* destination/dir
I'm looking for the equivalent command in windows.
What am I doing wrong?
for /f "delims=" %%a in ('dir /b /ad web_er*') do xcopy ".\%%a\*" "%WORKSPACE%" /e
should accomplish this. Process a directory list in /b basic (name-only) form /ad of directorynames matching web_er* in the current directory, and apply each name found in turn to %%a; then xcopy all of the files.
I ended up using the following powershell command:
Get-childitem | where {$_.name -like "Web_ER*"} | copy-item -recurse -destination ..\Ensure-Publish -force
So I just want to know if there's a way that I can get the name of the directory or a folder.
So for example I have these folders in my directory
test1_ew
test2_ter
test3_ew
So I just want to get the folders that have "_ew" on their names.
So basically I want to check all the folder names in my current directory if there's a _ew on their names.
If such folder(s) exist, I would like to run an executable file inside the folder(s).
Thank you in Advance!
Why not use IF EXIST if the text you are looking for will not change?
Here's an example:
C:\Scripts>for /f %a in ('dir c:\scripts\*s* /b /A:D') do echo %a
C:\Scripts>echo sccm
sccm
C:\Scripts>echo Test
Test
C:\Scripts>echo updates
updates
-Edit to add IF EXIST
C:\Scripts>for /f %a in ('dir c:\scripts\*s* /b /A:D') do if exist %a echo YES
C:\Scripts>if exist sccm echo YES
YES
C:\Scripts>if exist Test echo YES
YES
C:\Scripts>if exist updates echo YES
YES
You can use the Attribute switch /A: with the DIR command to specify you only want to look for a directory and use a wildcard for the directory name:
DIR C:\FOLDER\*_ew /B /A:D
You could also send this to a text file, for example on your desktop, like so:
DIR C:\FOLDER\*_ew /B /A:D > %USERPROFILE%\Desktop\TEST_OUTOUT.txt
note that if any of the paths used have spaces you will need to wrap them in quotation marks.
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 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)