Windows script to merge all .html files in a directory and its subdirectories into a single .html file? - merge

I have a Results directory, which has many subdirectories each containing a HTML file with a specific naming format, _ExeReport.html.
I want to write a Windows script which merges each of those files into one file.
For now, I tried running two commands :
dir /S *_ExeReport.html
This is listing all the files (with some extra information), and:
copy /b *.html final.html
This is merging all the files in current directory into one file.
But, I am not able to write a script which can combine and do everything I need.
Can someone help me with this? I am newbie to scripting languages.

Thanks to #T3RR0R for sharing the link. My final command :
FOR /F "tokens=*" %G IN ('dir /b /s *_ExeReport.html') DO TYPE "%G" >> MergedOutput.html

Related

Simple xcopy script using variables and a target text list to copy a folder to different computers

I wrote a script that wil copy a particular folder to a list of hosts, stored in a text file.
It works great from a short source path but fails to find the folder when located in a long path, which is how i need it to function.
Thsi what i tried, which should copy the folder to the list in the text.
Code below
set source=%~dp0%data
set source2=%~dp0%\target.txt
FOR /F "TOKENS=*" %%A IN (%source2%) DO XCOPY /d /y /f /i "%source%" "\%%~A\c$\users\test\test"
pause
Error: The system cannot find the file C:\Users\lenovo\OneDrive\Company\Red.
The above path is not the full path.
I understand there may well be more modern ways to achive this such as ropcopy or powershell and am open to ideas if this is not teh best method.
Thanks in advance for any help

Copy files in different subdirectories to another directory using a file list

so I have a list of about 26,000 files that I need Copied/moved to a different directory on a server. The different files in the list all have different sub-directory locations and names in the main source folder and the paths are specified in the filelist document.
The source filepath is on a network drive so (V:\RandomFolder\RandomSubdirectory)
The destination filepath would be on the local machine so (C:\RandomDestination)
I looked into seeing of robocopy could pull from the file list and move that way but I couldn't seem to find a way to make that work. Anyone got any ideas? I'd really appreciate any help.
Okay I figured it out, if anyone runs into this conundrum just follow like what is below( and edit to your liking and save it as a .bat
`#ECHO ON
SET FileList=C:\listoffilestomove.txt
SET Source=\\TopLevelOfNetworkOrFolderSourceDirectory\
SET Destination=C:\yourdestination
FOR /F "USEBACKQ TOKENS=*" %%F IN ("%FileList%") DO XCOPY /F /Y "%Source%\%%~F" "%Destination%\"
GOTO :EOF`

Copying files from similar multiple folders into each of their child folders

I would like to use a batch file to copy files in a folder to a backup folder (OLD) within, on a Windows server. And I want to do this for multiple folders.
So for example, I have multiple folders, named like this:
C:\A01
C:\A02
C:\A03
...
C:\A50
I will nickname them here as A##.
Each folder has hundreds of files.
Then each year before updating them, I copy those files into a backup folder called OLD, for each A##, so I have a backup of last year's files. Then I copy in new files into C:\A##, in another manual process, individually.
So there will be folders like:
C:\A01\OLD
C:\A02\OLD
C:\A03\OLD
...
C:\A50\OLD
When I do the copy, to the OLD folder, I keep the most recent version of each file. But then the files that I later manually copy in will overwrite in the C:\A## folder and be this year's files, while C:\A##\OLD will contain last year's files.
How can I script this so it will copy all the files for each C:\A## folder into their respective \OLD folder?
I assume I would use a variable for the path I want to copy from and to.
I could use Robocopy or Xcopy.
in a script file
#echo off
cd c:\
for /f "usebackq delims=:" %%a IN (`dir /AD /B ^| FINDSTR /I /R "A[0-9]*"`) DO (
#mkdir "%%a\OLD"
xcopy "%%a\*.*" "%%a\OLD\" /ECIFHRY /D
)
it copy only the updated files (/D) to the OLD subfolder.
if you want to mantain ACLs of the files, use /ECIFHRKOXY
I suggest you to test it in a test folder, that you can generate with this commands directly in the shell
#mkdir c:\test76
cd c:\test76
For /L %a IN (1,1,10) DO #mkdir A%a && echo "the quick brown fox jumps over the lazy dog">A%a\file.txt

CMD dir List video files - Not Found error

I crafted some command line code (function? I don't know the technical term, my apologies) that is meant to look in a network folder (and all it's subfolders) and only list the file path for those files that are a particular type. I tried to test it on a folder with less information in it first, however I got the error File Not Found. This confused me because I looked in the folder--there were definitely .VOB and .mp4 files in the specified folder.
When I run the code included below, I don't get the error, BUT I'm getting a bunch of files I don't want (.pdf .xml .jpeg--etc.) I think because they're system files such as the .jpeg files for the .avi thumbnails.
dir "\\nas-rb4b\projectx2" /s /b *.avi *.mov *.mp4 *.wmv *.mpg *.lnk *.ldb *.rar *.mpeg *.m4v *.vob *.zip>Projx2RERUN.txt
Can anyone help me understand why I got the File Not Found error when I tried to run the exact same code but with a different more specific folder?
I also don't know how to modify the code/function to exclude files that are not the listed file types and are not system folders. Any help is, as always, much appreciated!
Read the newest dir command reference in Windows Commands:
Syntax:
dir [<Drive>:][<Path>][<FileName>] [...] [/p] [/q] [/w] [/d] [/a[[:]<Attributes>]][/o[[:]<SortOrder>]] [/t[[:]<TimeField>]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]
Remarks:
To use multiple FileName parameters, separate each file name with a
space, comma, or semicolon.
The command in question dir "\\nas-rb4b\projectx2" /s /b *.avi *.mov *.mp4
(truncated) says and performs the following:
dir "\\nas-rb4b\projectx2" /s /b, (i.e. all files in "\\nas-rb4b\projectx2"), then
dir /s /b *.avi (i.e. all .avi files in the current directory), then
dir /s /b *.mov (i.e. all .mov files in the current directory), then
dir /s /b *.mp4 (i.e. all .mp4 files in the current directory), …
Solution (read pushd and popd reference as well):
pushd "\\nas-rb4b\projectx2"
dir /s /b *.avi *.mov *.mp4 *.wmv *.mpg *.lnk *.ldb *.rar *.mpeg *.m4v *.vob *.zip>Projx2RERUN.txt
popd
Following some advice from Ken White along with a combination of the answers given here, here, and information from here I made the expression below which eventually worked for me.
dir /b /s \\nas-rb4b\projectx2\*.avi \\nas-rb4b\projectx2\*.mov \\nas-rb4b\projectx2\*.mp4 \\nas-rb4b\projectx2\*.wmv \\nas-rb4b\projectx2\*.mpg \\nas-rb4b\projectx2\*.rar \\nas-rb4b\projectx2\*.mpeg \\nas-rb4b\projectx2\*.m4v \\nas-rb4b\projectx2\*.vob \\nas-rb4b\projectx2\*.zip
It is not pretty but it allowed me to search for multiple file types using only one expression and have their paths all sent to one txt file rather than searching each file extension individually.
So far it is working as intended.

Move files from multiple folders to a single folder without extension

i am a windows user and i need help with something
i have a folder and in it it has multiple folder.and in those multiple folders i have more folders and in those folder i have files without any extension like jpg,txt etc
here is a sample
D:\test\1\something1\1235486[file]
D:\test\1\something2\1235486[file]
D:\test\2\something1\1235486[file]
D:\test\2\something2\1235486[file]
so now i want to move all those random number files i.e 123456789[these files are without any extension] to D:\newtest
so i will have files like
D:\newtest\123456789
D:\newtest\123456789
D:\newtest\123456789
D:\newtest\123456789
etc. i could have easily done this with search option if it had a extension.but what can i do now?
Finally Found a solution for this problem
First make another folder where you want to transfer file
lets say i have a folder named ABC and i want to transfer its files to XYZ [only files not folders]
then open Command prompt [cmd]
and enter this
for /f "tokens=*" %a in ('dir /b /s /a-d "d:\abc"') do #copy "%a" "d:\xyz
Change the folder names and hit enter.it will transfer all the files in it