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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Script Help and Suggestions

Reply to Message Icon

Name: screamoon
Date: July 19, 2006 at 05:36:49 Pacific
OS: XP Pro. SP2
CPU/Ram: 512 mb
Product: 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




Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 19, 2006 at 14:28:49 Pacific
Reply:

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


0

Response Number 2
Name: screamoon
Date: July 20, 2006 at 02:40:47 Pacific
Reply:

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


0

Response Number 3
Name: screamoon
Date: July 20, 2006 at 03:05:23 Pacific
Reply:

I tried the above script

It is deleting all the files.

screamoon


0

Response Number 4
Name: Shr0Om
Date: July 20, 2006 at 04:08:59 Pacific
Reply:

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.


0

Response Number 5
Name: screamoon
Date: July 20, 2006 at 04:31:35 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: dtech10
Date: July 20, 2006 at 12:34:18 Pacific
Reply:

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.



0

Response Number 7
Name: vijayatluri
Date: September 6, 2006 at 07:59:26 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Script Help and Suggestions

Batch Script Help Needed www.computing.net/answers/programming/batch-script-help-needed/14475.html

Simple Batch Script help www.computing.net/answers/programming/simple-batch-script-help/12744.html

Batch Script Help www.computing.net/answers/programming/batch-script-help/15158.html