matthewst
(Getting the hang of it)
2005-12-21 06:48 PM
Deleteing specified files

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?


Gargoyle
(MM club member)
2005-12-21 07:27 PM
Re: Deleteing specified files

Use Readline() to read the "delete_these_files.txt"

Radimus
(KiX Supporter)
2005-12-21 07:35 PM
Re: Deleteing specified files

readfile() UDF

for each $file in readfile($filename)
del $file
next


matthewst
(Getting the hang of it)
2005-12-21 07:35 PM
Re: Deleteing specified files

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


matthewst
(Getting the hang of it)
2005-12-21 07:42 PM
Re: Deleteing specified files

I can't find readfile in the command reference

Gargoyle
(MM club member)
2005-12-21 07:47 PM
Re: Deleteing specified files

You can find it in the UDF forum
http://www.kixtart.org/UDF/


matthewst
(Getting the hang of it)
2005-12-21 07:55 PM
Re: Deleteing specified files

Thanks, I'm going to have a go at it.


I think I'm in over my head!!


matthewst
(Getting the hang of it)
2005-12-21 08:08 PM
Re: Deleteing specified files

OK, I am definitely in over my head. I'm such a noob.

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


matthewst
(Getting the hang of it)
2005-12-21 08:18 PM
Re: Deleteing specified files

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


Bryce
(KiX Supporter)
2005-12-21 08:23 PM
Re: Deleteing specified files

Code:

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



matthewst
(Getting the hang of it)
2005-12-21 08:35 PM
Re: Deleteing specified files

I can't get it to work


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


Radimus
(KiX Supporter)
2005-12-21 08:39 PM
Re: Deleteing specified files

first would be to have the full path in the file, however...

del 'C:\program files\'+$file


NTDOCAdministrator
(KiX Master)
2005-12-21 08:47 PM
Re: Deleteing specified files

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

 


matthewst
(Getting the hang of it)
2005-12-21 08:47 PM
Re: Deleteing specified files

Ok, I changed that but I am still having no luck.
Thanks for all your help.
I'll keep trying.


Radimus
(KiX Supporter)
2005-12-21 08:49 PM
Re: Deleteing specified files

try posting what you have... telepathy is hard when the weather is this cold

matthewst
(Getting the hang of it)
2005-12-21 08:58 PM
Re: Deleteing specified files

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


Les
(KiX Master)
2005-12-21 10:11 PM
Re: Deleteing specified files

I assume the UDF code is in there somewhere.

del 'C:\program files\'+$file


NTDOCAdministrator
(KiX Master)
2005-12-21 10:26 PM
Re: Deleteing specified files

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

 


matthewst
(Getting the hang of it)
2005-12-22 01:17 PM
Re: Deleteing specified files

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


matthewst
(Getting the hang of it)
2005-12-22 01:40 PM
Re: Deleteing specified files

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?


Radimus
(KiX Supporter)
2005-12-22 02:12 PM
Re: Deleteing specified files

try this:
change
Del 'C:\Program Files\'+$File

to:
? 'C:\Program Files\'+$File
Del 'C:\Program Files\'+$File
? @error +' '+@serror

also, does your people have local admin?


matthewst
(Getting the hang of it)
2005-12-22 02:24 PM
Re: Deleteing specified files

No, they are all regular users, but I can't get it to run for me either.
I'll make the changes and report back...


Radimus
(KiX Supporter)
2005-12-22 02:27 PM
Re: Deleteing specified files

they will probably not have permission to delete those files then...

matthewst
(Getting the hang of it)
2005-12-22 02:32 PM
Re: Deleteing specified files

A step in the right direction...well a direction anyway!!

This is the output I get when I run it in a dosbox
Code:
C:\test.kix

C:\Program Files\File1
2
C:\Program Files\
2
C:\

matthewst
(Getting the hang of it)
2005-12-22 02:41 PM
Re: Deleteing specified files

Do I need a comma or semicolon in delete_these_files.txt?

File1,
or
File1;


matthewst
(Getting the hang of it)
2005-12-22 03:27 PM
Re: Deleteing specified files

tried both the comma and the semicolon, they were just a step backwards

Radimus
(KiX Supporter)
2005-12-22 03:40 PM
Re: Deleteing specified files

BTW... when you say file are you meaning folder

Be specific


matthewst
(Getting the hang of it)
2005-12-22 03:43 PM
Re: Deleteing specified files

yea, sorry about that.
stupid question of the day: does that make a difference?


Radimus
(KiX Supporter)
2005-12-22 03:56 PM
Re: Deleteing specified files

Del
Action: Deletes one or more files.
http://www.scriptlogic.com/Kixtart/htmlhelp/Commands/del.htm

RD
Action: Removes the directory specified.
http://www.scriptlogic.com/Kixtart/htmlhelp/Commands/rd.htm

and yes, it makes a difference


Radimus
(KiX Supporter)
2005-12-22 04:00 PM
Re: Deleteing specified files

and if they do not have admin, then they will probably have have the permissions to delete those files, unless the acls have been played with...

GIGO


Radimus
(KiX Supporter)
2005-12-22 04:06 PM
Re: Deleteing specified files

since GIGO has come up.

Are you just trying to remove installed programs by deleting the directories?


LonkeroAdministrator
(KiX Master Guru)
2005-12-22 04:07 PM
Re: Deleteing specified files

you clearly don't have a File1 in your program files folder if it says there is no such file in the error.

Gargoyle
(MM club member)
2005-12-22 04:11 PM
Re: Deleteing specified files

Your file should specify full filenames with the extension

Also run it with debug so you can see exactly what it is doing at what point.


matthewst
(Getting the hang of it)
2005-12-22 04:14 PM
Re: Deleteing specified files

not trying to uninstall, just remove some directories
also i changed del to rd and now i get this output
Code:
c:\test.kix

C:\Program Files\Directory1
145
c:\Program Files
145
C:\

Radimus
(KiX Supporter)
2005-12-22 04:42 PM
Re: Deleteing specified files

if you READ the links that I provided, RD only works on empty directories

so you will need to provide directory names in your file.
and do something like:

for each $d in readfile($file)
del "%programfiles%\"+d$+"\*.*" /s /c
rd "%programfiles%\"+d$ /q
next


Radimus
(KiX Supporter)
2005-12-22 04:42 PM
Re: Deleteing specified files

btw... as funny as it would be, make sure there are no blank lines in your text file.

Mart
(KiX Supporter)
2005-12-22 04:43 PM
Re: Deleteing specified files

Error 145: The directory is not empty.
@SERROR would also show this

Have a look here for all error codes and a short explanation.
System Error Codes


matthewst
(Getting the hang of it)
2005-12-22 05:30 PM
Re: Deleteing specified files

thanks everyone for all your help, we're getting there!!!


now i get ERROR : undifined variable [$d]!
Line : 11

i tried changing the delete_these_files.txt to read $dDirectory
then i tried changing the $d in the scrip to $file and still no luck


LonkeroAdministrator
(KiX Master Guru)
2005-12-22 05:38 PM
Re: Deleteing specified files

heh, no, the $d is the file.
you have somewhere a dim $file line?
change that to $d.


matthewst
(Getting the hang of it)
2005-12-22 05:43 PM
Re: Deleteing specified files

so far i have this in my script
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)
? 'C:\Program Files\'+$File
for each $File in readfile($file)
del "C:\Program Files\"+$File+"\*.*" /s /c
rd "C:\Program Files\"+$File /q
next

? @error +' '+@serror
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



this in my delete_these_files.txt
Code:
$FileDirectory



and this is th output
Code:
C:\test.kix
c:\Program Files
-1
c:\



Radimus
(KiX Supporter)
2005-12-22 05:55 PM
Re: Deleteing specified files

For Each $File In ReadFile('\\Server\Share\delete_these_files.txt')
If Exist('C:\Program Files\'+$File)
? 'C:\Program Files\'+$File
del "C:\Program Files\"+$File+"\*.*" /s /c
? @serror
rd "C:\Program Files\"+$File /q
? @serror
endif
next


matthewst
(Getting the hang of it)
2005-12-22 06:01 PM
Re: Deleteing specified files

just the dim $file, or all the $file?

LonkeroAdministrator
(KiX Master Guru)
2005-12-22 06:05 PM
Re: Deleteing specified files

Quote:

this in my delete_these_files.txt
Code:
--------------------------------------------------------------------------------

$FileDirectory





wtf?
the txt file was supposed to have the darn directory names in there.

slow down and carefully plan the steps to take.
it's not as complex as it looks.


matthewst
(Getting the hang of it)
2005-12-22 06:18 PM
Re: Deleteing specified files

i get an error in expression line 13
if i remove the q i get
Code:
C:\test.kix

C:\Program Files\Directory
The system cannon find the file specified.
The directory is not empty.
C:\Program Files
Access is denied.
The directory is not empty.
C:\



I am admin on the local machine and i know the
name of the directory is correct


Radimus
(KiX Supporter)
2005-12-22 06:30 PM
Re: Deleteing specified files

show the contents (at least some) of the file
show the code
show the error


matthewst
(Getting the hang of it)
2005-12-22 06:32 PM
Re: Deleteing specified files

Quote:

wtf?
the txt file was supposed to have the darn directory names in there.




It does, that was just one of the many things I have tried to get this to work
some of the directories are:
pics from home
my profile.backup
hotties

basicly just a bunch of junk
one of the other admins on base
told my users to save there personal
junk under program files


matthewst
(Getting the hang of it)
2005-12-22 06:52 PM
Re: Deleteing specified files

here is everything i have
test.kix
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)
? 'C:\Program Files\'+$File
del "C:\Program Files\"+$File+"\*.*" /s /c
? @serror
rd "C:\Program Files\"+$File /q
? @serror
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



here is the delete_these_files.txt file
Code:
hotties



and here is the error i get when running the script
Code:
C:\test.kix

C:\Program Files\Directory
The system cannon find the file specified.
The directory is not empty.
C:\Program Files
Access is denied.
The directory is not empty.
C:\



also the script deletes itself each time i run it


Gargoyle
(MM club member)
2005-12-22 07:10 PM
Re: Deleteing specified files

When you run the script use the following:
Code:

c:\myscripts\kix32 myscript.kix /d



This will allow you to step through the script and see what it is doing on each line and you can look at what the variables are being set to .

Read up on the Debug section in the manual.


matthewst
(Getting the hang of it)
2005-12-22 08:08 PM
Re: Deleteing specified files

it stopped deleting itself all the time
now if i can just figure out how to remove a
directory that has files and folders in it i'll be set


Gargoyle
(MM club member)
2005-12-22 09:18 PM
Re: Deleteing specified files

If you are running it in Debug mode when you get to this line
del "C:\Program Files\"+$File+"\*.*" /s /c

pay attention to what the error code returned is.

Using the ? @serror should tell you exactly why it is not deleting the files. From the output you posted earlier it is returning Access is denied.

If this continues to hold true, look at what the permissions for that directory are for the account that is running the script.


matthewst
(Getting the hang of it)
2005-12-23 02:32 PM
Re: Deleteing specified files

it says access denied, but the funny thing is
i can delete it manualy....i can even create a
directory myself then try to delete it with the
script and i still get access denied


matthewst
(Getting the hang of it)
2005-12-23 02:43 PM
Re: Deleteing specified files

correction!!
if i create a directory and it is empty it works...well it
deletes the dir anyway
the output is
Code:
C:\test.kix
C:\Program Files\tester
The system cannot find the file specified.
The operation completed successfully
C:\Program Files



however if i put something in the directory it fails
to delete it and i get the system cannot find the file specified and the dir is not empty errors


LonkeroAdministrator
(KiX Master Guru)
2005-12-23 02:47 PM
Re: Deleteing specified files

well, you are trying to delete "c:\program Files" as one.
I know that someone might wanna do that, but that's why you get the error 5.

deletion of non-empty dir is currently supported only by 4.52 beta 1.


matthewst
(Getting the hang of it)
2005-12-23 03:05 PM
Re: Deleteing specified files

what do i need to change in the script to only delete the specified directories in program files

LonkeroAdministrator
(KiX Master Guru)
2005-12-23 03:52 PM
Re: Deleteing specified files

change your loop:
Code:

For Each $File In ReadFile('\\Server\Share\delete_these_files.txt')
If Exist('C:\Program Files\'+$File)
? 'C:\Program Files\'+$File
del "C:\Program Files\"+$File+"\*.*" /s /c
? @serror
rd "C:\Program Files\"+$File /q
? @serror
endif
next



to:
Code:

For Each $File In ReadFile('\\Server\Share\delete_these_files.txt')
If Exist('C:\Program Files\'+$File) and len(join(split($File),""))
? 'C:\Program Files\'+$File
rd "C:\Program Files\"+$File /s
? @serror
endif
next



note, this rd /S need the new beta.


matthewst
(Getting the hang of it)
2005-12-23 04:16 PM
Re: Deleteing specified files

the air force only allows us to use 4.11

btw: Thanks to everyone for there help so far


LonkeroAdministrator
(KiX Master Guru)
2005-12-23 04:29 PM
Re: Deleteing specified files

k, then you can add your lines back.
Code:

For Each $File In ReadFile('\\Server\Share\delete_these_files.txt')
If Exist('C:\Program Files\'+$File) and len(join(split($File),""))
? 'C:\Program Files\'+$File
? 'Deleting Files -> '
del "C:\Program Files\"+$File+"\*.*" /s /c
@serror
? 'Removing the Directory -> '
rd "C:\Program Files\"+$File /q
@serror
endif
next



matthewst
(Getting the hang of it)
2005-12-23 04:55 PM
Re: Deleteing specified files

getting closer!!!

here is my test.kix
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) and len(join(split($File),""))
? 'C:\Program Files\'+$File
? 'Deleting Files -> '
del "C:\Program Files\"+$File+"\*.*" /s /c
@serror
? 'Removing the Directory -> '
rd "C:\Program Files\"+$File
@serror
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



my delete_these_files.txt
Code:
pics from home
my profile.backup
hotties
tester



and here is the output (when the tester dir is empty) (tester is a dir i creted myself to test the scrip)
Code:
c:\test.kix

C:\Program Files\pics from home
Deleting Files -> Access is denied.
Romoving the Directory -> The directory is not empty.
C:\Program Files\my profile.backup
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The Directory in not empty.
C:\Program Files\hotties
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The Directory in not empty.
C:\Program Files\tester
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The operation completed sucessfully.



when the tester dir is NOT empty i get
Code:
C:\Program Files\tester
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The directory is not empty



I can manualy delete the files so I'm sure it's not a permissions problem.


LonkeroAdministrator
(KiX Master Guru)
2005-12-23 05:08 PM
Re: Deleteing specified files

so, you had kix 4.11?

LonkeroAdministrator
(KiX Master Guru)
2005-12-23 05:13 PM
Re: Deleteing specified files

Quote:


Fixes/enhancements in 4.20:
...
- Added recursion ('/s') to COPY and DEL





so, change:
del "C:\Program Files\"+$File+"\*.*" /s /c

to:
del "C:\Program Files\"+$File+"\*.*" /c


matthewst
(Getting the hang of it)
2005-12-23 05:41 PM
Re: Deleteing specified files

a little better
now i get this
Code:
c:\test.kix

C:\Program Files\pics from home
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The directory is not empty.
C:\Program Files\my profile.backup
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The Directory in not empty.
C:\Program Files\hotties
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The Directory in not empty.
C:\Program Files\tester
Deleting Files -> The system cannot find the file specified.
Removing the Directory -> The operation completed sucessfully.



no more "Access is Denied"


LonkeroAdministrator
(KiX Master Guru)
2005-12-23 05:48 PM
Re: Deleteing specified files

what you have in such dirs that it says can't find the file?

NTDOCAdministrator
(KiX Master)
2005-12-23 07:36 PM
Re: Deleteing specified files

Well if you can't use a newer version of KiX then just SHELL out and use RD /S /Q for what you want to remove.

Files in use can not be removed though. Be quite careful too as any mistakes may render a system non bootable.
 
Always use some type of LEN or other command to verify you're not at the root of the drive.
 


Radimus
(KiX Supporter)
2005-12-23 10:25 PM
Re: Deleteing specified files

Still won't let me live that one down, eh Doc...

:-)


NTDOCAdministrator
(KiX Master)
2005-12-23 10:42 PM
Re: Deleteing specified files

LOL - no names mentioned. I've actually written my own complete code that did not check the length of the var and removed way too much data

Les
(KiX Master)
2005-12-24 12:35 AM
Re: Deleteing specified files

Then there was my disastrous BBChecker uninstall that wiped out my entire HD.

LonkeroAdministrator
(KiX Master Guru)
2005-12-24 12:42 AM
Re: Deleteing specified files

I was waiting for that old memory to come alive.
iirc, it was about the uninstaller script and how it was called and les didn't talk to me for a while...


matthewst
(Getting the hang of it)
2005-12-26 03:26 PM
Re: Deleteing specified files

just a thought, what about deltree.exe

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

Dim $File
For Each $File In ReadFile('\\szl-fs9ces1\roxio\delete_profiles.txt')
If Exist('C:\Documents And Settings\'+$File)
shell "deltree /y 'C:\Documents and Settings\$File'"
endif


this doesn't work
how do i shell a something that has quotes in the command?


Radimus
(KiX Supporter)
2005-12-26 03:31 PM
Re: Deleteing specified files

shell 'deltree /y "C:\Documents and Settings\$File"'

Les
(KiX Master)
2005-12-26 03:59 PM
Re: Deleteing specified files

shell 'deltree /y "C:\Documents and Settings\' + $File + '"'

NTDOCAdministrator
(KiX Master)
2005-12-26 04:00 PM
Re: Deleteing specified files

Try again Rad

He is using:
$SO=SetOption('NoVarsInStrings','On')


NTDOCAdministrator
(KiX Master)
2005-12-26 04:01 PM
Re: Deleteing specified files

oops I see Canada is up

Les
(KiX Master)
2005-12-26 04:03 PM
Re: Deleteing specified files

There are a few FAQs on the use of SHELL and quotes.

Radimus
(KiX Supporter)
2005-12-26 04:25 PM
Re: Deleteing specified files

i hate novars...

matthewst
(Getting the hang of it)
2005-12-26 04:28 PM
Re: Deleteing specified files

that doesn't seem to work, I also tried:
Run 'deltree /y "C:\Documents and Settings\$File"'


Les
(KiX Master)
2005-12-26 04:49 PM
Re: Deleteing specified files

read on...

matthewst
(Getting the hang of it)
2005-12-26 05:09 PM
Re: Deleteing specified files

I can get it to work this way
shell 'deltree /y "C:\Documents and Settings\dir_to_delete"'
but i can't seem to get it to recognize $File


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

Dim $File

shell 'deltree /y "C:\Documents and Settings\Dir_to_delete"'



this doesn't
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)
shell 'deltree /y "C:\program files\' + $File + '"'
endif





NTDOCAdministrator
(KiX Master)
2005-12-26 07:22 PM
Re: Deleteing specified files

Well DELTREE is not a valid program on 2000/XP/2003 but the RD command is as I've shown before.

The following code should work just fine on Windows NT/2000/XP/2003 as long as the user has Administrator rights on the system and there are no files locking the profile.
 


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

Dim $Profiles,$Profile,$BadProfiles,$File
$Profiles=ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList','ProfilesDirectory'))
'Profiles are stored here: ' + $Profiles ?
$File = '\\szl-fs9ces1\roxio\delete_profiles.txt'
$BadProfiles = ReadFile($File)
'Reading profiles from ' + $File ?
'Read error: ' + @ERROR + ' ' + @SERROR ?
For Each $Profile In $BadProfiles
If $Profile
If GetFileAttr($Profiles+'\'+$Profile) & 16
'Bad Profile found: ' + $Profile ?
;Remove the semi-colon from the SHELL line below to actually delete the profile
If Len($Profiles+'\'+$Profile)>10
;SHELL '%COMSPEC% /C RD /S /Q ' + '"'+$Profiles+'\'+$Profile+'"'
EndIf
'Error removing profile: ' + @ERROR + ' ' + @SERROR ?
EndIf
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

 


NTDOCAdministrator
(KiX Master)
2005-12-26 07:25 PM
Re: Deleteing specified files

Quote:

i hate novars...






ROFL now - now ... That's just lazy coding. You're letting Ruud take up the slack for you inside the EXE.
 


NTDOCAdministrator
(KiX Master)
2005-12-27 12:16 AM
Re: Deleteing specified files

Quote:

can get it to work this way
shell 'deltree /y "C:\Documents and Settings\dir_to_delete"'





What operating systems are we talking about here? I certainly hope the Air Force or whomever is not still running Windows 95/98 systems in production.

DELTREE does not exist on my NT4/2000/XP/2003 systems so if it's working (semi-working) for you then we must be talking about a Windows 95/98/ME system which would mean the RD code I wrote would not work either as Windows 95/98 used a different switch as I recall.
 


LonkeroAdministrator
(KiX Master Guru)
2005-12-27 10:00 PM
Re: Deleteing specified files

doc, my 100,000 USD is on him not reading all the replies and not really seeing that his syntax is wrong.

Sealeopard
(KiX Master)
2005-12-31 04:03 PM
Re: Deleteing specified files

To delete a directory, use RD. And upgrade to KiXtart 4.52 beta 1 to utilize the RD /S switch.

And read the FAQ Forum with regards to e..g using UDFs.


NTDOCAdministrator
(KiX Master)
2005-12-31 08:20 PM
Re: Deleteing specified files

I know you found some free time and are updating posts Jens, but you missed the part where he says he can't upgrade his KiX version. Thus the RD code of CMD.EXE

Sealeopard
(KiX Master)
2005-12-31 11:35 PM
Re: Deleteing specified files

Darn, yes, found the Air Farce Force reference

Guess, they need to certify the newer KiXtart versions first