I have been trying to write a .bat
program which will find all the files with a given extension, for example *.doc, and will put them into a rar
archive.
I want all the files to be copied even if they have the same name (I have files with the same name in different directories) I don't care if the files will be renamed as long as I keep all of them. For example, if I have a new.doc
in Desktop
and another new.doc
in D:
, I don't care if one of the two or even both are renamed new1.doc
or new2.doc
or any other way. Alternatively, the program can save them using the path it found them in. The use of rar
over 7-zip
or any other compression program is preferred but if really necessary, using another program is OK. Last but not least, I want the program to search the entire computer (all the hard disks). For example, I have
C:
, D:
and F:
and I want to search all 3 and to create the archive D:\test.rar
. I have tried several solutions and have gotten as far as
for %%i in (c: d: f:) do for /f "delims=" %%j in ('dir /s /a-d /b %%i\*.doc') do "C:\Program Files\WinRAR\Rar.exe" a d:\test.rar "%%~j"
Now my problem is that in some PCs it works OK but in some it finds fewer files than actually exist. I find the total number of files searching for *.doc
and compare the number found to the number of .doc
files in the archive. I have no idea why some files are not found. Any insights or comments will be greatly appreciated.