Computing.Net > Forums > Programming > Batch Script Help and Suggestions

Batch Script Help and Suggestions

Reply to Message Icon

Original Message
Name: screamoon
Date: July 19, 2006 at 05:36:49 Pacific
Subject: Batch Script Help and Suggestions
OS: XP Pro. SP2
CPU/Ram: 512 mb
Model/Manufacturer: Xenon
Comment:

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)d

Now 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



Report Offensive Message For Removal


Response Number 1
Name: dtech10
Date: July 19, 2006 at 14:28:49 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: screamoon
Date: July 20, 2006 at 02:40:47 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: screamoon
Date: July 20, 2006 at 03:05:23 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

I tried the above script

It is deleting all the files.

screamoon


Report Offensive Follow Up For Removal

Response Number 4
Name: Shr0Om
Date: July 20, 2006 at 04:08:59 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

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\%%a

Is like:
FOR every line GET "STRING" in (Files.txt) do COMMAND on "STRING"


This would fix the problem
del Output\*.* /A-h

This 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.


Report Offensive Follow Up For Removal

Response Number 5
Name: screamoon
Date: July 20, 2006 at 04:31:35 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

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


Report Offensive Follow Up For Removal


Response Number 6
Name: dtech10
Date: July 20, 2006 at 12:34:18 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

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.



Report Offensive Follow Up For Removal

Response Number 7
Name: vijayatluri
Date: September 6, 2006 at 07:59:26 Pacific
Subject: Batch Script Help and Suggestions
Reply: (edit)

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


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch Script Help and Suggestions

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge