I have two folders. I want to compare the files inside these folders.There are some subfolders in root folders. These sub folders are also containing some files. I want to compare these files in subfolder also. For that I am trying to write a batch file. Any kind of solution will help me a lot
I would not use a batch file at all to accomplish this task. BeyondCompare is here to do exactly that, and does it seemingly well.
Now on the other hand you really wanna do it via batch file, I'd suggest you install a tool called diff tools, and you'll be able to do something like:
diff.exe <file1> <file2> <htmlfile>
On the command line.
hope it helps
UPDATE
As a follow up to your comment, I write this, which also seems to work for me, and doesn't use any external tool. This is a simple example, but you can make it better.
if exist compare.log del compare.log
if exist missing.log del missing.log
for /f "delims=" %%a in ('dir/b/a-d c:\test\1') do (
if exist "C:\test\2\%%a" (
fc "c:\test\%%a" "C:\test1\%%a" >> compare.log
) else (
echo %%a is missing >> missing.log
)
)
Pause
try dir /b /s
to search for files within subdirectory, instead of dir /b
Related
I already looked at this site and others for an answer, but I could not find any, so here is my simple question. I have a dvd which has several folders (named after the respective years) in it. Inside each of those there are subfolders, which then again have subfolders. So it basically looks like this:
2001/Projectabc/sub1
/sub2
/sub3
2002/Projectdef/sub1
/sub2
.. and so on.
I now need a batchfile that listst me all the Projectnames without anything else and writes them inside the textfile, so that in the end I would have a fiule lookin like this:
Projectabc
Projectdef
So basically what I don't know is how do write the batch, so that it only lists the second level Foldernames.
I started like this:
dir [Directory of dvd]:\..\ /b /a:d >> C:\folderlist.txt, saved this as a bat file, executed it, opened my folderlist.txt and have
_01.2003
_01.2004
_01.2005
_01.2008
_01.2009
_01.2010
_01.2011
_01.2013
_01.2014
I really am stuck, since I am a newbie. Thanks very much everyone, who might help.
Let's assume your DVD is in drive G: (change the code to fit your scenario)
The following one liner will work from the command line:
>c:\folderlist.txt (for /d %A in (g:\*) do #for /d %B in ("%A\*") do #echo %~nxB)
Or using a batch file:
#echo off
>c:\folderlist.txt (
for /d %%A in (g:\*) do (
for /d %%B in ("%%A\*") do echo %%~nxB
)
)
On my machine I cannot write to the system root, so I would have to change the destination folder for the output.
I have a good command over cmd commands, but this may require a variable or a loop which is where I fail in batch commands. Please help if you can!
-- Have about 100 subdirectories each has 1-20 HTML files in it. There are about 100 HTML files in the root directory too.
-- Need to replace all HTML files in the above directories with the same HTML source (copy over existing file and keep the name the same). Basically trying to replace all existing files with a redirect script to a new server for direct bookmarked people. We are running a plain webserver without access to server-side redirects so trying to do this just by renaming the files (locked down corp environment).
Seems pretty simple. I can't get it to work with wildcards by copying the same file over to replace. I only get the first file replaced, but the rest of the files will fail. Any one with any advice?
This should do it from the command prompt. Replace % with %% for use in a batch file.
for /r "c:\base\folder" %a in (*.html) do copy /y "d:\redirect.html" "%a"
Without knowing more precisely how you want to update the file content I suggest the following rough approach.
To re-create your example, I had to create some folders. Run this command to do that:
for /l %i in (1,1,20) do mkdir fold%i
I then used this script to create some example files:
#echo off
set number=0
for /d %%i in (c:\Logs\htmltest\*) do call :makefiles %%i
goto :EOF
:makefiles
set /a number+=1
touch %1\file%number%.txt
echo %number% >%1\file%number%.txt
I then used this script to append the text changed to the file. Not sure if that is what you wanted - probably you need something more sophisticated.
#echo off
set number=0
for /d %%i in (c:\Logs\htmltest\*) do #for %%f in ("%%i\*.txt") do call :changetext %%f
goto :EOF
:changetext
echo changing file contents to ^"changed^" for file: %1
echo changed>>%1
If that title wasn't confusing enough.. hopefully what I am trying to do is a lot simpler to understand.
Windows 7 just in case it needs to be said.
I have multiple directories within the folder I am working in;
C:\WorkingDir\1
C:\WorkingDir\2
C:\WorkingDir\3
and so on
Within each of these folders (1,2,3,etc) is a single sub-directory and no other files or folders;
C:\WorkingDir\1\5E04AB
C:\WorkingDir\2\4F07FC
C:\WorkingDir\3\9DA04F
I need to move each of those single subdirectories from within the parent folder to a new folder;
C:\NewFolder\5E04AB
C:\NewFolder\4F07FC
C:\NewFolder\9DA04F
That's it! I thought it might be simple, but I can't wrap my head around the variables or a better resource explaining how to use them. I don't use batch files much if at all, so I am very sorry for this cry for help. Hopefully someone more knowledgeable has a simple explanation that can help me out :-)
I found this: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true
But can someone link me to a resource where I can learn more about batch variables and parameters for future reference?
Thank you thank you thank you
Update:
#endoro
Thanks for your response. There must have been a user error the first time I tried to run your code. It is working properly and all is well! Thank you so much!
Update 2
After running the code User1 contributed, It will create my NewFolder directory, but will not copy anything to it. It remains empty. Here is some of the repetitive output in DOS when I run it:
C:\WorkingDir>(
set fldr2=C:\WorkingDir\1\5E04AB
move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.
C:\WorkingDir>(
set fldr2=C:\WorkingDir\2\4F07FC
move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.
C:\WorkingDir>(
set fldr2=C:\WorkingDir\3\9DA04F
move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.`
Please look at the output and remove the echo, if it is OK:
#echo off &setlocal
set "workingdir=WorkingDir"
md "C:\NewFolder" 2>nul
pushd "%workingdir%"
cd
for /d %%i in (*) do for /d %%j in ("%%~i\*") do echo move "%%~fj" "C:\NewFolder\%%~nxj"
popd
I haven't been able to test this but:
#echo off
setlocal EnableDelayedExpansion
md "c:\NewFolder\"
cd "C:\WorkingDir\"
for /D /r %%a in ("*") do (
set fld1=%%a
cd "%fld1%"
for /D /r %%b in ("*") do (
set fld2=%%b
move "c:\WorkingDir\%fld1%\%fld2%" "C:\NewFolder\%fld2%"
)
)
And a good resource for batch:
http://ss64.com/nt/
I'm trying to copy several files from several folders into 1 folder with this code:
for /R \\wiki\help\images %%f in (*.jpg, *.png, *.gif) do (
copy %%f "\\10.101.3.21\wikitest\wiki\wikiimages"
)
However, it copies all the files as wikiimages, and I can't get around it. I just want to use the copy command, not an external program (so no xcopy or the like). How can I do this?
I'm pretty sure
for /R \wiki\help\images %%f in (*.jpg, *.png, *.gif) do copy %%f "\10.101.3.21\wikitest\wiki\wikiimages\"
is the way to fix this, it usually need the \ to know its a folder and not a filename.
I'm trying to make a simple batch script but it keeps failing. I want to look for each file in a directory (basepath) and put each file in a separate rar archive.
If I use "%%~ni.rar" in the rar line, he puts all files in all archives. SO for n files i get n archives with in each archive the n files. [also he doesnt seem to put the archives in [c:\test*.*] but rather puts them in the location of the batch file.
If I use "%%i.rar" it creates two different archives, but then the filenaming is totaly wrong: f.e: testfile.jpg >> testfile.jpg.rar and thats not how i would like it (testfile.rar instead)
#ECHO OFF
CLS
SET BASEPATH=c:\test
SET RARExe=c:\PROGRA~1\WinRAR\RAR.EXE
FOR %%i IN (%basepath%\*.*) DO %RARExe% a -m0 "%%~ni.rar" c:\test\*.*
FOR %%i IN (%basepath%\) DO mkdir c:\test\%%~ni
Goto :eof
can someone help me out?
I found how to do it, actually an easy solution.
FOR %%i IN (%basepath%\*.*) DO (
rar a -ep1 -t -m0 c\test\%%~ni.rar %%i
)