Need to copy and rename files in different folders - batch-file

would anyone know how to write a batch file (or two) that would:
copy hundreds of "index.html" files that are in different folders and keep within the same folder (so needs to search within sub folders)
rename the copies (keep the originals as is) to "index.jpg"
could anyone help?

I used a bulk rename tool to rename all index.html files to index.jpg in a copy of the main folder, then used robocopy to copy everything over, including the file structure back to the original folder (leaving the index.html's alone)

Related

How to move files based on characters left to the file extension to a subfolder?

Since I do not have a lot of experience in coding batch files, I would like to ask for some helping hands.
There are multiple files in the source folder. The files list is like this.
ABCD_CH_DEFGH.XLS
ABCD_CH_DEFGH.PDF
ABCD_CH_DEFGH_001_001.XLS
ABCD_CH_DEFGH_001_001.PDF
QWER_DE_OPESADHXCS_002_002.XLS
QWER_DE_OPESADHXCS_002_002.PDF
I would need a batch file which iterates through the files in the source folder and moves only files with the substring _xxx_xxx. to an existing subfolder which are in this case:
ABCD_CH_DEFGH_001_001.XLS
ABCD_CH_DEFGH_001_001.PDF
QWER_DE_OPESADHXCS_002_002.XLS
QWER_DE_OPESADHXCS_002_002.PDF

How to look at the contents of a zipped folder in batch?

In this case, I have a zip folder with contents inside. How would I look into the zip folder and be able to check the file name of those files for a certain word without having to unzip the file to begin with?
So for example:
I have a zip folder with the files inside named
123456789COW.txt
123445614COW.txt
123456789ASK.txt
232436787CAT.txt
and I want to check if the file has COW inside the name.
Every solution I have found so far has assumed I know the contents already, but in my case that may not always be true and I need to check.

Accidentally copied folder and files into a single file

An ms-dos backup batch file has copied all files and subfolders from a single folder into a single file on a usb stick. Is there any way we can extract theses files and folders from the single file that was created?
I believe what you probably did was the equivalent of
copy f1.txt d:\backup\backupfile
copy f2.txt d:\backup\backupfile
copy f3.txt d:\backup\backupfile
which, since backupfile isn't a directory, copied all 3 files, successively, to the file d:\backup\backupfile.
Unfortunately, this means that first f1.txt was copied to that file, then f2.txt, then f3.txt. Since each copy overwrote the file, I think you'll find that the contents of backupfile are equivalent to f3.txt (the last file that was backed up). If you have already deleted f1 and f2.txt, then they're gone.

How to exclude a specific file from being copied using xcopy

I'm new to Windows batch files, but I'm writing a .bat file that just copies a bunch of files from one place to another maintaining the file directory structure. Using xcopy this is simple but I need to exclude some files from being copied. You can use /exclude and create a text file full of strings that you want to be excluded, but this doesn't just exclude files with the exact names in the text file, it excludes all files whose filenames contain any of the strings in the text file.
What this means is, if I want to exclude any files named 123.txt and put this string in my exclusions text file, if there was a file called 1123.txt anywhere in the source folder or any of its subfolders that would also be excluded.
How can I exclude only files with a specific filename from being copied?
Evening Bill.
Can you add a slash before each file name? That should work
EG
instead of
123.txt
blah.txt
use
\123.txt
\blah.txt
Try creating a temporary folder, xcopying all of the files into that folder, deleting the ones you don't want, then xcopying those to the final destination. Finally, delete the temporary folder and its contents with rd xyzzy /q/s

Command Prompt and batch files

I'm trying to copy a number of files from a directory. I want to include the file path from the base of this particular directory tree, however, I only have a list of the file names to go by. Is there a way to copy either:
a list of files with their directories appended to the beginning in a .txt file
a copy of the folders in the directory with copies of the files placed in their original places in the original directory.
Each file in the directory has a unique name.
I've looked all over google, but the closest I've found is xcopy, which I don't believe is capable of this.
Thanks!
For the second option you can use xcopy /s or robocopy /s. Both are great tools for this kind of job.

Resources