Window Batch file to keep some specific folders and delete the rest - batch-file

I have 100+ folders, and I want to run a batch file to keep certain folders like 10 folders with different names based on my list. Example I have folders like
1FL-12
1FL-44
1FL-86
2FL-95
2FL-73
2FL-25
3FL-52
4FL-53
4FL-35
5FL-85
I am trying to keep only the folder 2FL-95, 2FL-73 and 2FL-25 and delete the rest. Before I tried using rmdir /S /Q "C:\pathtodirectory" to delete the unwanted ones but its not that convenient when there are just too many folders to delete.
Is there any simpler way to keep only the folders and delete the rest?

Related

How to rename PDFtk-server files with timestamp?

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.

Move all the contents of a folder with a .bat

I using the following syntax to move all the files inside a folder, to another folder
set OGGI=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%
move C:\DOCUMENTALE\dms_in\*.* C:\DOCUMENTALE\dms_backup\%OGGI%\
This syntax is working with files, but which syntax I have to use if I would move also folders?
The problem is that this path C:\DOCUMENTALE\dms_in\ contains folders automatically generated. I don't know how many folders there are in or which names they have.
I did some attempt but I didn't figure it out
Thanks
An solution to this is to use the command ROBOCOPY instead. It is arguable more flexible.
ROBOCOPY <source> <destination> /MOV /E
/MOV will move the file/folder in question instead of the default copy.
/E will allow you to mirror the directory structure of the target folder if there are any folders within the folder including empty ones
Note: you may need to use quotation marks for the source and destination if either path contains spaces.
Another neat feature of Robocopy is that it will show you what is it doing; what is being copied and too where, how long it takes etc. And if it goes wrong due to paths for example, it will tell you.
You can also browse ss64.com for more help and examples to fit your needs.

Create a batch file to create multiple folders within many folders

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"

seting up a template folder copy/ past system with batch

I have a foldering system setup consisting of a “master folder” wich varys in name holds two sub folders, the sub folders though are always called CTB and DWG. I want the contents. of the DWG folder always to be coppied to the desktop and the contents of the CTB to always be coppied to C:\ICT\Autocad_2010\CTB. Remembering that the master folder varys in name pending on the project.
Is this possible with batch?
somthing like:
XCOPY %0\DWG\*.* c:\ICT\AutoCAD_2010\CTB
Nevermind i got it
XCOPY "%cd%\DWG\*.DWG" c:\
however how do i copy it to the desktop?
try this to copy to the current user desktop
xcopy "dwg\*.dwg" "%Homedrive%%Homepath%\desktop"
or this to copy to all users desktop
xcopy "dwg\*.dwg" "%allusersprofile%\desktop"

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