1.

Solve : Batch Script for Reading text, removing and copying?

Answer»

Hi guys,

I am extremely new to batch scripts and just WROTE my own batch script a few moments ago to SIMPLY open a file.

I am using Windows 7!

What I WANT to do:

I want to create a batch script which:
1. Reads a text file in a folder on my desktop and then searches for the files listed inside a destination folder and removes them if they exist (The list has a lot of files)
2. It then brings up a prompt which asks which batch script I would like to use next in the same source folder on the desktop. I would answer this by pressing a number which is assigned to each batch script i.e. the number 1 executes ENB1.bat etc.

The purpose of the next batch script would be to again read the contents of the file Line-by-Line and copy them into the destination folder with the same name.
And then, take make to the destination file.

Some HELP:-

Source File of Text files and the Batch: C:\Users\User Name\Desktop\Skyrim Batch Files

The Following Files are inside the "Skryim Batch Files" Folder:

Batch Scripts: Remove All ENBs.bat, ENB1.bat , ENB2.bat , ENB3.bat
Text File checked to remove files: Remove ENBs.txt
Text File to Copy ENB's: ENB1 Files.txt , ENB2 Files.txt , ENB3 Files.txt

This isn't inside "Skyrim Batch Files" Folder:

Destination Folder: : D:\Skyrim - Copy

So Remove All ENBs.bat would check the destination folder for the files in Remove ENBs.text and remove them
2.The command prompt would then ask me which batch file I would like to execute next and it would look like this:

"Which Batch Script would you like to execute next?:" 1. ENB1 2. ENB2 3. ENB3

By pressing 1, it runs ENB1.bat. By pressing 2, it runs ENB2.bat etc

The ENB.bat files also read seperate text documents respectively which are: ENB1.bat ---> ENB1 Files.txt, ENB2 ---> ENB2 Files.txt, ENB3.bat ---> ENB3 Files.txt
They would then copy each PROGRAM written on one line each and then put them in the destination folder

Then the program would end.

I might be asking for a lot, but I would appreciate it if you could help me make the script. I would love you even more if you used my exact file names haha

Thanks for all the help!

~ Brya



This assumes certain things about the text files.

"Remove ENBs.txt" contains program names only and is not quoted.

Each other text file contains on each line the drive:\path\filename.ext and is not quoted.

The 4 batch files are below:


Code: [Select]:: Remove All ENBs.bat
@echo off
for /f "delims=" %%a in ( ' type "Remove ENBs.txt" ' ) do (
del "D:\Skyrim - Copy\%%a" 2>nul
)
set var=
set /p "var=Which Batch Script would you like to execute next?: 1. ENB1 2. ENB2 3. ENB3 "
call enb%var%.bat

::ENB1.bat
@echo off
for /f "delims=" %%a in ( ' type "ENB1 files.txt" ' ) do (
echo copying "%%a"
copy /b "%%a" "D:\Skyrim - Copy" >nul
)

::ENB2.bat
@echo off
for /f "delims=" %%a in ( ' type "ENB2 files.txt" ' ) do (
echo copying "%%a"
copy /b "%%a" "D:\Skyrim - Copy" >nul
)

::ENB3.bat
@echo off
for /f "delims=" %%a in ( ' type "ENB3 files.txt" ' ) do (
echo copying "%%a"
copy /b "%%a" "D:\Skyrim - Copy" >nul
)

*censored*

Thankyou for all the help. I should have stated if the paths were quoted but thatnkyou for specifying they weren't

You have saved me a lot of time and space.

Thankyou very much!



Discussion

No Comment Found