Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am looking for some help in writing a batch script. What I want to do is suppose that I have a text file with contents as:
1)a
2)b
3)c
4)dNow in some folder C:\Output I have some files with extension say .1
I want to delete all other files from that folder Output apart from the files listen in the Text file.
That means I want a script that would leave only those files which are listed in that text file and delete all others.
Help would be highly appreciated.
Thanks and Regards
screamoon

Hi Scremoon
@echo off
for /f %%a in (Files.txt) do attrib +h Output\%%a
del Output\*.*
for /f %%a in (Files.txt) do attrib -h Output\%%a

As I understand you have used the Hidden attribute. You deleted all others which are not hidden and after deleting removed the hidden attribute.
May I please ask as to what part of the script is comparing the file names in the text file to those of the file names in the folder ?
screamoon

The FOR command will do an operation for every line in the txt file.
"for /f %%a in (Files.txt) do SOMETHING"
The variable %%a contains the string read from Files.txt
So this:
for /f %%a in (Files.txt) do attrib +h Output\%%aIs like:
FOR every line GET "STRING" in (Files.txt) do COMMAND on "STRING"
This would fix the problem
del Output\*.* /A-hThis will delete all files except the files that has the Hidden attribute
Still, im not so sure if that FOR command can handle filenames with spaces between then. You should check that out. Might be the FOR command needs to modified somewhat.

I modified my script as you suggested Shr0Om. But still I am getting this error :
( screenshot of the error I am getting )http://img.photobucket.com/albums/v308/scream123456/error.jpg
i.e. a File Not Found Error
And my file names are going to be like:
000000fa4a02cf80-0000-0cf5-94050a25
The names do not contain spaces but would be having a "-".
screamoon

Hi Scremon
The Files you don't want deleted are in the Files.txt file which from the above would contain...
1)a
2)b
3)c
4)d
If these files are hidden a del command would should not see them.
Then unhiding them again should make then visable again.

Hi
Any one can help me in regarding
1) to disable usb ports from bios by running the batch script
2) and it must also disable usbports except mouse
Thanks
vijayatluri

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |