Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file 1

Status
Not open for further replies.

cswamy1

IS-IT--Management
Apr 4, 2001
20
US
Hi

I have a Folder (A) with all files and respective names of files are written in a name.text file in a different folder(B).

All users will be using some application which will keep adding files to A and respective files names will be written after certain period (say 2 days) to name.txt. Meaning folder A may have 1000 files but name.txt may contain only 800 names.

As the volume of files are increasing we would like to remove all the files whose names match in name.txt. This should happen every week. SO we would like to use batch program for it.

Can any one help me in creating this.

Thanks in advance

reg
 
As far as I know there is no abililty of a batch file to use a list of files for delete.

A small program, some shells or scripts could.

It is really not too difficult. Here's a solution in BASIC

If you have a TrueBASIC that works in DOS environments the 8 line program below takes in the file list and produces a file of delete commands. Not too many more lines in C or C++.

[tt]
type delete_file.List| DelList> delfiles.bat
delfiles
[/tt]

dellist.bas
Code:
DECLARE FUNCTION gstdin$ CDECL ()
 a$ = gstdin$()
 WHILE a$ <> CHR$(3)
   PRINT &quot;del &quot;; a$
   a$ = gstdin$()
 WEND
END

KixTart might do the deletes for you.

You could also use The River, two lines in a batch file:

type delfiles.txt| Prepline &quot;del &quot; $$lin >deletes.bat
deletes

There are lots of similsr approaches. Are such methods possible?
 
You can do this is a batch file using the FOR IN DO command.

Try this:

c:
cd\a
FOR /F %%g IN (Name.txt) DO move /y %%g c:\b

That will move all files listed in c:\a\file.txt from c:\a to c:\b. NB The default FOR IN DO uses space as a delimiter so this would fail if your filenames have spaces in. (This can easily be fixed though). Also it does not clear the moved files from the Name.txt - but that is easy to do too.

Hope that helps!

rich
 
Excellent, Even the COTES documentation on NT FOR does not have that.

I did find a way for non-nters, a batch file that emulates the /F in NT FOR, although the BAT file is a lot longer than a program to do similar.


So it looks like all Wins can get to do this and save the bother of a program.

One can always learn.
 
Thanks all for great input. It worked for me.

reg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top