mass deletion batch file - windows

I have been tasked with stripping out around 50 thousand .INI files from a windows folder that has 58 thousand files in it the issue is that the files aren't in order and removing these manually would be very time consuming.
The files themselves use number Id's as their naming convention and I managed to get an Excel spreadsheet together with all the ID's I need to remove. My question is, can I put these ID's somewhere like a batch file and get it to remove these if so how?
Thanks in advance.

Here is the simplest script that will work:
cd "C:\directory\location\"
del "*.ini" /s
exit
The first line makes sure its in the directory that all the files are in, the second one deletes all the files in the specified folder and all of its subfolders (the subfolders can keep their .ini files if you remove the /s), and the third line quits the batch file. The third line is not necessary. The first line can be revoked if the batch file (.bat) is in the same folder as all of the .ini files.

Related

Use drag and drop function to select multiple files and process all

I need a way to select several files with check-boxes and drag them all to a batch-file icon. The first step in the script would be to be compressed them into a single zip file before proceeding to the next step. If possible, it would be useful to also end up with each in a separate zip of its own for storage.
I am not sure how to address the for:to commands to allow gathering all selected files into a single zip file in a script. The Windows 'sendto compressed zip' function works perfectly if I select all the files the copy and paste them to the Windows ZF filetype. But I don't know how to access it from within a batch.
Drag and drop multiple files
By default, if you drag a file onto a batch file it is the same as passing the filepath as a parameter. This can be accessed using %%1. Dragging multiple files would have a similar effect and be like calling test.bat file1.txt file2.txt file3.txt. Each "parameter" can be accessed using subsequent variables, %%1, %%2, %%3, etc, up to %%9.
Get more information here.
Zipping files
First you will need a utility that supports command line operations, such as 7-zip. Once you have the appropriate executable in your path, you will need to review the documentation on how to zip files from the command line. Instead of using the paths and filenames, you will use the variables mentioned above.
Here is some pseudo code:
zipfiles output.zip %%1 %%2 %%3 %%4 %%5
Notes
You will not be able to drop more than 9 files.
You may need to confirm that each variable exists. If you try to include %%9 in the zip command but you only dropped 8 files, you may get an error.

Get location (path) of the shorctut calling a batch file

I have an ongoing list of 'Enquiry' folders within a directory. I'm trying to create a batch file that can sit within each of these folders that, when run, will move the folder it resides in to a 'Projects' folder.
From my attempts, and as half expected, I'm realising it's not possible to move the folder containing the batch file (or copy folder and then delete source folder containing the batch), so my second thought is to position a single 'master' batch file outside of the 'Enquiry' folders, and have a shortcut within each Enquiry folder that links to that 'external' batch file.
For this, I'd need to obtain the location path of the shortcut calling the batch, is this possible?
Or is there a better way to achieve my aim?
Just an extra note in case it helps anyone, I had to make the following changes to ensure file path with space was ok (putting %enqfolder% in quotes) and I also need to a '\' after 'projects' in the move command. Thanks again to #Klitos.
setlocal
set enqfolder=%cd%
cd ..
move "%enqfolder%" ..\projects\
Following on from the comments to your question, the reason it doesn't move the folder is that when the batch file runs, the current directory is still the enquiry folder. You need to move out of it and then move it. Also, as it turns out, you don't have to delegate to a "master" batch file either. You can just do the move in the same batch file (but the move should be the last line of the batch file; once the batch file itself moves, the command processor won't be able to read the following lines).
setlocal
set enqfolder=%cd%
cd ..
move %enqfolder% ..\projects

Batch file to copy files from multiple folders to a single folder, overriding if date is newer

I would like to be able to copy all files from various folders and combine them into a single folder using a Windows batch file. That is fairly easy to do for me. But if the file already exists on the destination, I would like it to only override the file if it's newer.
copy c:\pics\ to d:\
Thanks.
You can use xcopy for more options if the source dirs are 2-3-5 (write separate xcopy lines for each). If the dirs are too many, you can use archiver like WinRar (or its command line rar.exe) with #list option where are stored the source dirs. In the batch file call RAR 2 times - first to pack all source files to one archive, then to unrar them in single folder (with E option, not X). Finally, you delete the .rar file. See the extra options to skip older files, omit prompts, etc.

creating a batch file

I would like to creat a batch file that will recognise folders date moidified in a network drive and then copy them to another network drive
while I was searching I found way to do that to files, but I need it for folders
I didn't find a way to do that
Sadly, you didn't say which method you'd found. If that method selects the files using a DIR.../a-d... structure for instance, then omit the - before the d and directories matching the selected pattern rather than files would be processed.
To create a batch file just get notepad++ and save as a .bat, is that what you meant? or did you want a certain type of Batch file, because I didn't think there was another type unless you count Command prompt and Notepad++ different?
Forfiles may be helpful, or robocopy
This will create a mirror backup in the destination folder. If files are deleted in the source then they will also be deleted in the destination.
#echo off
robocopy "\\172.172.172.10\folder" "\\172.172.172.2\destination" /mir

DOS Commands- Excluding files in a folder in xcopy

I have a folder containing many other sub-folders.
I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using "xcopy" for this. I am facing following problem:
The folder structure is as shown below-
--FolderB1
---FolderB2
---FolderB22
---File1.txt
---File2.txt
---File3.txt
I have some .txt files inside "FolderB1", along with "FolderB2" and
"FolderB22" I want to copy "FolderB2" and "FolderB22" and skip ".txt"
files contained in "Folder B1"
I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of ".txt" files. Have checked this question too, but did not help.
Alternate method or other pointers for the same would be a great help. Thanks in advance.
What you could try to do is to hide the files you don't want to copy, then execute the xcopy, and then unhide the files again.
Look at my answer of question Windows batch script to delete everything in a folder except one. That question was related do deleting files (excluding some files), but you can probably use the same trick for xcopy-ing files.

Resources