Please can someone help with the below
I have two folders:
C:\FolderA
C:\FolderB
Folder A contains a bunch of files like an archive
Folder B contains the same bunch of files with the same name, however some data within the files may be different.
I want to write a .bat file which uses the diff command to compare all the files from folder A to the files in folder B with the corresponding name (e.g. update0001 against update 0001) and outputs the difference in "C:\Folder C" with each file difference in a separate text output. (e.g one file is called “Error update0001” and another “Error Update0005”
This is a simple way to check the files in two folders and give results.
fc /b "c:\folder a\*.*" "c:\folder b\*.*" >"c:\folder c\results.txt"
Related
I am using PDFtk-server to merge 2 PDF files. This creates a new PDF with name Test_.
Now, what I am looking for is a batch files that renames the Test_ files to Test_datestamp and then move them into another folder and delete the files.
It is working if only one file is present.
pdftk C:\test\*.pdf C:\test\file-to-add\file.pdf cat output C:\test\output\Test_.pdf
ren "C:\test\output\*pdf" "Test_ - %date:/=.% %time::=-%.pdf"
del C:\test\*.pdf
Then comes to copy part to other folders.
If having multiple files, the first one gets renamed but other not, because it is trying to set the same timestamp, so I need some kind of delay between renaming.
I have 2 identical folder trees, let's call them C:\First and C:\Second, with many subfolders. C:\First has many XML files in many sub and sub-sub folders. C:\Second just has the folder tree created.
I want to go through all XML files in C:\First\* and put it in it's equivalent place in C:\Second.
But first I want to check if a file with the same name exists in the C:\Current folder (no subfolders there), in which case I will copy the one from C:\Current to the proper sub-sub-sub folder in C:\Second.
In other words, I want to copy the whole structure and files from C:\First to C:\Second but I want to take the latest version that may or may not exist in C:\Current. And, in C:\Current there are many files I don't care about.
Example:
C:\Current has these files:
a.xml
b.xml
1.xml
c.xml
d.xml
e.xml
2.xml
f.xml
g.xml
3.xml
In C:\First I have a.xml, b.xml, c.xml, d.xml, e.xml, f.xml, g.xml spread out in its sub-folders.
I hope I'm not being too confusing...
When a problem is properly stated, the same problem description may serve as specifications to write the program. In your case, you have this description:
I want to go through all XML files in C:\First* and put it in it's
equivalent place in C:\Second.
But first I want to check if a file with the same name exists in the
C:\Current folder
The "But first" doesn't serve to write a program. You just need to write the first things in first place! For example:
I want to go through all XML files in C:\First*. I want to check if a
file with the same name exists in the C:\Current folder in which case
I will copy the one from C:\Current to the proper sub-sub-sub folder
in C:\Second. Otherwise put the file from C:\First in it's equivalent
place in C:\Second.
The pseudo-code below is an example of how your original problem description may be translated into a program:
rem I have 2 identical folder trees, let's call them C:\First and C:\Second, with many subfolders.
rem C:\First has many XML files in many sub and sub-sub folders. C:\Second just has the folder tree created.
rem I want to go through all XML files in C:\First\*
for /R inside C:\First with all *.XML files do (
rem But first I want to check if a file with the same name exists in the C:\Current folder (no subfolders there)
if exist "C:\Current folder\place here just the name of the file from the for command" (
rem in which case I will copy the one from C:\Current to the proper sub-sub-sub folder in C:\Second.
set properFolder=place here the sub-sub-sub folder from the for command
set properFolder=change "C:\First" by "C:\Second" in properFolder
copy "C:\Current folder\just the name" "!properFolder!"
) else (
rem ... and put it in it's equivalent place in C:\Second.
set properFolder=place here the sub-sub-sub folder from the for command
set properFolder=change "C:\First" by "C:\Second" in properFolder
copy "the file from for command" "!properFolder!"
)
)
If you analyze this code you will realize that the lines that get properFolder are the same in both parts, so a simpler method would be to get properFolder just one time before the if command.
You may use this pseudo-code as starting point to write your Batch file.
I searched this site but all the examples I found were when someone wanted to merge all the files into only 1 file.
I'm on Win 7 x64.
I have 2 folders with 250 text files in each and the filenames (of the text files) across both folders are the same.
Example:
Folder A:
file001.txt
file002.txt
file003.txt
Folder B:
file001.txt
file002.txt
file003.txt
The contents in all these files (and across folders), are different. The filenames themselves vary greatly, too (I just named them like above for example purposes).
Now I want to merge the files from Folder A into the files from folder B.
I want to do this:
Merge FolderA\file001.txt to FolderB\file001.txt
Merge FolderA\file002.txt to FolderB\file002.txt
etc.
So if file001.txt (Folder A) had 500 lines and file001.txt (Folder B) had 300 lines, after the merge file001.txt (Folder B) should have 800 lines.
Right now I'd have to open the file in Folder A, copy all, go to folder B, open the 2nd file, paste, save. For 250 files that's just too much.
Does anybody know of a way to batch merge text files from different folders as explained above?
I'd just love to select all 250 files in folder 1, copy them, paste into folder 2 and have them all merged to their counterparts...but I guess a solution like that doesn't exist. If you know of a program or batch command that does this, I'm all ears.
For %%a in (Folder1\*.txt) do type "%%~a" >> "Folder2\%%~nxa"
Hi, I have many zip files located at g:\toto. These zips contain some files. I would like to extract all zip in a same directory (g:\toto\extracted) then rename various files of the zip.
Example 1 :
www_12567.vp.zip : 3 files : alpha.doc, beta.xls, teta.doc
I would like after extraction, files are renamed with the name of the zip
www_12567.vp.alpha.doc, www_12567.vp.beta.xls, www_12567.vp.teta.doc
Example 2 :
www_12.vp.zip : 3 files : al.doc, bea.xls, tta.doc
www_12.vp.al.doc, www_12.vp.bea.xls, www_12.vp.tta.doc
I found this question, but it talks about .txt and the zip contain one file, so, it doesn't work.
Without knowing the contents of the archive you can't know which files to rename, because you are putting them into a directory that may already contain other files.
This, however, would be much easier if there was a dedicated directory to put the files temporarily. Here's how you could use it:
#ECHO OFF
SET "srcdir=G:\toto"
SET "tgtdir=G:\toto\extracted"
SET "tmpdir=G:\toto\extracted-tmp"
FOR %%Z IN ("%srcdir%\*.zip") DO (
unpack "%%Z" with your favourite tool into "%tmpdir%"
FOR %%I IN ("%tmpdir%\*") DO MOVE "%%I" "%tgtdir%\%%~nZ.%%~nxI"
)
Of course, the temporary directory would need to be empty before running the batch file. You could add DEL "%tmpdir%\*" somewhere before the loop to make sure it is.
One other note is, the above assumes that the archives do not contain subdirectories or, at least, that the files are extracted without subdirectories.
UPDATE
If you are using the 7-Zip archiver to work with .zip files, then this is how your extract command might look:
7z e "%%Z" -o"%tmpdir%"
Disclaimer: I'm not an active user of 7-Zip. This is what I used as a reference to come up with the above command:
7-Zip Command-Line Examples
I am trying to create a batch file which will create folders within all sub-folders of a given folder. So for example if it ran in the directory C:\Example, it would create a folder a, b, and c under each of the 20 folders regardless of their name.
It would be much easier to do this automatically rather than copy the .bat file to every individual folder to create the 5 same folders every time with just md.
So far everything I have created has been a disaster, so I'm hoping someone can help me out with this.
for /d %%x in (*) do mkdir "%%x\a" "%%x\b" "%%x\c"