Page 1 of 5 12345>
Topic Options
#153766 - 2005-12-21 06:48 PM Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
Heres an easy one. I need a script that will delete certain files. The tricky part is the name of the files that need to be deleted will change from time to time. I need the script to look in a "delete_these_files.txt" file (stored remotly), read the names to the files to delete, then delete them.

Any suggestions?

Top
#153767 - 2005-12-21 07:27 PM Re: Deleteing specified files
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Use Readline() to read the "delete_these_files.txt"
_________________________
Today is the tomorrow you worried about yesterday.

Top
#153768 - 2005-12-21 07:35 PM Re: Deleteing specified files
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
readfile() UDF

for each $file in readfile($filename)
del $file
next
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153769 - 2005-12-21 07:35 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
Thanks! I think that's what I've been looking for.

I just read the syntax and I'm completely lost. I am going to be using this to clean out some old program files at login. All I need is this

Kix goes to "\\remote_machine\delete_these_files.txt"
reads the names of the files (sometimes 1, sometimes 100)
then deletes them if they exists on the local machine

Top
#153770 - 2005-12-21 07:42 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
I can't find readfile in the command reference
Top
#153771 - 2005-12-21 07:47 PM Re: Deleteing specified files
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
You can find it in the UDF forum
http://www.kixtart.org/UDF/
_________________________
Today is the tomorrow you worried about yesterday.

Top
#153772 - 2005-12-21 07:55 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
Thanks, I'm going to have a go at it.


I think I'm in over my head!!

Top
#153773 - 2005-12-21 08:08 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
OK, I am definitely in over my head. I'm such a noob.

I don't even know how to get started on this.

Top
#153774 - 2005-12-21 08:18 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
where do i put the path and name of the delete_these_files.txt

then how to i get the names it just read into the del $files thingy

Top
#153775 - 2005-12-21 08:23 PM Re: Deleteing specified files
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Code:

for each $file in readfile('c:\delete_these_Files.txt')
del $file
next


Top
#153776 - 2005-12-21 08:35 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
I can't get it to work


for each $file in readfile('\\server\c$\delete_these_files.txt')
del C:\program files\$file
next

Top
#153777 - 2005-12-21 08:39 PM Re: Deleteing specified files
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
first would be to have the full path in the file, however...

del 'C:\program files\'+$file
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153778 - 2005-12-21 08:47 PM Re: Deleteing specified files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Have you ever run a script?

You create a text file and put your code in the text file.
Then you save the file typically with a .KIX extension.
Then run it like this (assuming you have KIX32.EXE in C:SCRIPTS folder)


C:\SCRIPTS\KIX32.EXE MyNewScript.KIX

It will then process what you have in the script file.

The ReadLine is a UDF and there is an FAQ here on the board to show you how to use them.

Basically you add the code portion of the UDF to your script and call it.
You DO NOT modify the UDF code

Example:
ReadFile($file) for you to call would be
ReadFile('C:\SCRIPTS\FileToDelelete.txt')

 

Top
#153779 - 2005-12-21 08:47 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
Ok, I changed that but I am still having no luck.
Thanks for all your help.
I'll keep trying.

Top
#153780 - 2005-12-21 08:49 PM Re: Deleteing specified files
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
try posting what you have... telepathy is hard when the weather is this cold
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#153781 - 2005-12-21 08:58 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
I've written a few simple scripts, but never used a udf before.
I thought this would be something simple. Sorry about that.

This is all I have. Obviosuly I'm missing something.


for each $file in readfile('\\server\c$\delete_these_files.txt')
del 'C:\program files\'$file
next

Top
#153782 - 2005-12-21 10:11 PM Re: Deleteing specified files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I assume the UDF code is in there somewhere.

del 'C:\program files\'+$file
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#153783 - 2005-12-21 10:26 PM Re: Deleteing specified files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Try something like this.


Modify to your values and make sure users have access to the file(s) to read and delete.
 
 
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $File
For Each $File In ReadFile('\\server\someshare\delete_these_files.txt')
If Exist('C:\program files\'+$File)
Del 'C:\program files\'+$File
EndIf
Next


Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=CHR(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction

 

Top
#153784 - 2005-12-22 01:17 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
Ok, here is what I have now.

Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $File
For Each $File In ReadFile('\\Server\Share\delete_these_files.txt')
If Exist('C:\Program Files\'+$File)
Del 'C:\Program Files\'+$File
EndIf
Next


Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=CHR(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction



and here is what the delete_these_files.txt looks like
Code:
file1



i still can't to get it to work
the script runs without errors, but it doesn't delete anything

Top
#153785 - 2005-12-22 01:40 PM Re: Deleteing specified files
matthewst Offline
Getting the hang of it

Registered: 2005-01-26
Posts: 89
I read through the udf faq and still don't see the problem with the code.
Has anyone else been able to get something like this to work?

Top
Page 1 of 5 12345>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.076 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org