SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Deleteing files from a directory using "f

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Deleteing files from a directory using "f
Author Message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Deleteing files from a directory using "file Reply with quote

I just started using 24x7, and I have been able to develop some small programs. But, I am having trouble with this one. I need to navigate to a directory, and delete the files that are there using a "file mask". These directories are on network servers,(\\***\***\winnt\system32\spooler\printers,*.spl) If anyone can assist me in this I would appreciate it.

Mon Feb 26, 2001 12:05 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7948

Post Re: Deleteing files from a directory using "f Reply with quote

You can do this in several steps.

First you get the list of directories in the root dir ("DIR \\\\???").

Then you loop through the list and for each file check whether it is a directory (FileGetAttr ..., IfThen ...). If no, you skip it, otherwise you search the subdir (Concat, DIR ...)

Repeat check for file types in subdir list to filter directories (like you did for root dirs)

For every directory you append "\\winnt\\system32\\spooler\\printers,*.spl" and do FileDeleteEx ... using the calculated mask

Here is the raw template (you need to add declarations of variables)

Dir "DIR \\\\???", root_list
GetToken ",", root_list, file_name
isEqual file_name, "", finish
LoopUntil finish, END_LOOP1

FileGetAttr file_name, attr

BitWiseAdd attr, 16, is_dir

IfThen is_dir, SEARCH_SUBDIR

// get next file

GetToken ",", root_list, file_name

isEqual file_name, "", finish

Continue

SEARCH_SUBDIR:

// get list of subdir and loop through

ConcatEx "\\\\", file_name, "\\???", sub_dir_mask

Dir sub_dir_mask, subdir_list

GetToken ",", subdir_list, file_name2

isEqual file_name2, "", finish2

LoopUntil finish2, END_LOOP2

FileGetAttr file_name2, attr2

BitWiseAdd attr2, 16, is_dir

IfThen is_dir, SEARCH_FILES

// get next file

GetToken ",", sub_dir_list, file_name2

isEqual file_name2, "", finish2

Continue

// now build the final file mask and delete files

SEARCH_FILES:

ConcatEx "\\\\", file_name, "\\", file_name2, "\\winnt\\system32\\spooler\\printers,*.spl", file_mask

FileDeleteEx file_mask, count

GetToken ",", sub_dir_list, file_name2

isEqual file_name2, "", finish2

END_LOOP2:

GetToken ",", dir_list, file_name

isEqual file_name, "", finish
END_LOOP1:

You can use the JAL DIR statement to get the list of directories that match your first path, then use it again to get

: I just started using 24x7, and I have been able to develop some small
: programs. But, I am having trouble with this one. I need to navigate to a
: directory, and delete the files that are there using a "file
: mask". These directories are on network
: servers,(\\***\***\winnt\system32\spooler\printers,*.spl) If anyone can
: assist me in this I would appreciate it.

Mon Feb 26, 2001 1:06 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

This is the code for the job as I understand it, but it still does not work. I must have a declaration or some syntax wrong.

I AM TRYING TO DELETE *.SPL FILES.
I can reach the Network drive either by \\MC1\C$\WINNT\SYSTEM32\SPOOL\PRINTERS
or
O:\WINNT\SYSTEM32\SPOOL\PRINTERS the files that I am searching for are *.spl. files.

dim root_list, string
dim file_name, string
dim is_dir, boolean
dim attr, number
dim finish, boolean
dim finish2, boolean
dim file_name2, string

Dir "DIR\\\\???", root_list
GetToken ",", root_list, file_name
isEqual file_name, "", finish
LoopUntil finish, END_LOOP1

FileGetAttr file_name, attr

BitWiseAnd attr, 16, is_dir

IfThen is_dir, SEARCH_SUBDIR

// get next file

GetToken ",", root_list, file_name

isEqual file_name, "", finish

Continue

SEARCH_SUBDIR:

// get list of subdir and loop through

ConcatEx "\\\\", file_name, "\\???", sub_dir_mask

Dir sub_dir_mask, subdir_list

GetToken ",", subdir_list, file_name2

isEqual file_name2, "", finish2

LoopUntil finish2, END_LOOP2

FileGetAttr file_name2, attr2

BitWiseAdd attr2, 16, is_dir

IfThen is_dir, SEARCH_FILES

// get next file

GetToken ",", sub_dir_list, file_name2

isEqual file_name2, "", finish2

Continue

// now build the final file mask and delete files

SEARCH_FILES:

ConcatEx "\\\\", file_name, "\\", file_name2, "\\winnt\\system32\\spool\\printers\*.spl", file_mask

FileDeleteEx file_mask, count

GetToken ",", sub_dir_list, file_name2

isEqual file_name2, "", finish2

END_LOOP2:

GetToken ",", dir_list, file_name

isEqual file_name, "", finish
END_LOOP1:


Mon Feb 26, 2001 3:09 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7948

Post Re: Deleteing files from a directory using "f Reply with quote

Change Dir "DIR\\\\???" to Dir "\\\\???"
Note that ? wildcard character substitutes just one symbol. As I understood your original message that you are interested only in directories that contain 3 letters in their name. If it is wrong, please use Dir "\\\\*" for the loop 1 and use ConcatEx "\\\\", file_name, "\\*", sub_dir_mask for the loop 2.

: This is the code for the job as I understand it, but it still does not work.
: I must have a declaration or some syntax wrong.

: I AM TRYING TO DELETE *.SPL FILES.
: I can reach the Network drive either by
: \\MC1\C$\WINNT\SYSTEM32\SPOOL\PRINTERS
: or
: O:\WINNT\SYSTEM32\SPOOL\PRINTERS the files that I am searching for are *.spl.
: files.

: dim root_list, string
: dim file_name, string
: dim is_dir, boolean
: dim attr, number
: dim finish, boolean
: dim finish2, boolean
: dim file_name2, string

: Dir "DIR\\\\???", root_list
: GetToken ",", root_list, file_name
: isEqual file_name, "", finish
: LoopUntil finish, END_LOOP1

: FileGetAttr file_name, attr

: BitWiseAnd attr, 16, is_dir

: IfThen is_dir, SEARCH_SUBDIR

: // get next file

: GetToken ",", root_list, file_name

: isEqual file_name, "", finish

: Continue

: SEARCH_SUBDIR: // get list of subdir and loop through

: ConcatEx "\\\\", file_name, "\\???", sub_dir_mask

: Dir sub_dir_mask, subdir_list

: GetToken ",", subdir_list, file_name2

: isEqual file_name2, "", finish2

: LoopUntil finish2, END_LOOP2

: FileGetAttr file_name2, attr2

: BitWiseAdd attr2, 16, is_dir

: IfThen is_dir, SEARCH_FILES

: // get next file

: GetToken ",", sub_dir_list, file_name2

: isEqual file_name2, "", finish2

: Continue

: // now build the final file mask and delete files

: SEARCH_FILES: ConcatEx "\\\\", file_name, "\\",
: file_name2, "\\winnt\\system32\\spool\\printers\*.spl",
: file_mask

: FileDeleteEx file_mask, count

: GetToken ",", sub_dir_list, file_name2

: isEqual file_name2, "", finish2

: END_LOOP2: GetToken ",", dir_list, file_name

: isEqual file_name, "", finish
: END_LOOP1:

Mon Feb 26, 2001 3:29 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

I have made the changes, but I still get the same message, Line #9, error in starting file search operation. As for the directory that I want to search it is always the same directory, no matter which server I am searching. I know where the files are, I am trying to automate a process to delete them. I don't know if this helps in any way. P.S. Thank you for the prompt response.

Mon Feb 26, 2001 3:49 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7948

Post Re: Deleteing files from a directory using "f Reply with quote

Then the thing you want to do is as simple as just 2 lines of code

Dim count, number
FileDeleteEx "\\\\MC1\\C$\\WINNT\\SYSTEM32\\SPOOL\\PRINTERS\\*.SPL", count

That's all

: I have made the changes, but I still get the same message, Line #9, error in
: starting file search operation. As for the directory that I want to search
: it is always the same directory, no matter which server I am searching. I
: know where the files are, I am trying to automate a process to delete
: them. I don't know if this helps in any way. P.S. Thank you for the prompt
: response.

Mon Feb 26, 2001 4:17 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

I have tried this before, and I tried it again. But I get the error message
"Error deleteing file 00189.spl"

File 00189.spl is the first file in the folder.

: Then the thing you want to do is as simple as just 2 lines of code

: Dim count, number
: FileDeleteEx
: "\\\\MC1\\C$\\WINNT\\SYSTEM32\\SPOOL\\PRINTERS\\*.SPL", count

: That's all

Mon Feb 26, 2001 4:34 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

I have learned the reason that I get the error, I have to change the attributes of the files from "read Only"

Is there an easy way of doing this?

: I have tried this before, and I tried it again. But I get the error message
: "Error deleteing file 00189.spl"

: File 00189.spl is the first file in the folder.

Mon Feb 26, 2001 4:57 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7948

Post Re: Deleteing files from a directory using "f Reply with quote

You can use "Dir" to get the list of files, then loop through the list and use "FileSetAttr" to reset the "read-only" property

: I have learned the reason that I get the error, I have to change the
: attributes of the files from "read Only"

: Is there an easy way of doing this?

Mon Feb 26, 2001 5:40 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

I tried that but I keep getting an Error message "File not found".

You can use "Dir" to get the list of files, then loop through the
: list and use "FileSetAttr" to reset the "read-only"
: property

Tue Feb 27, 2001 9:09 am View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

Here is copy of my Code. I have tried several different methods, but I am still unable to get past the "FILE Not found" Error.

dim count, number
dim file_name, string
dim found, string
dim attr, number
dim Read_only, number
dim list, string

Dir ("I:\\WINNT\system32\spool\PRINTERS\*.*", list)
FileSetAttr("I:\\WINNT\system32\spool\PRINTERS\*.spl" , 0 )

GetToken( ",", list, file_name )
FileSetAttr( file_name, 0 ) // This is where the error occurs.

//FileGetAttr( file_name, attr )
//
//BitWiseAnd attr, 2, Read_only
//
//IfThen Read_only, Change_attr
//
//Change_attr:

//FileDeleteex( "\\MC1\C$\WINNT\system32\spool\PRINTERS\*.spl", count )

Tue Feb 27, 2001 12:58 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7948

Post Re: Deleteing files from a directory using "f Reply with quote

FileSetAttr does not work with file masks!
Here is the code you are looking for

dim file_name, string
dim done, boolean
dim list, string

// get list of files
Dir ("I:\\WINNT\system32\spool\PRINTERS\*.spl", list)
// loop and process file by file
isEqual( list, "", done )
LoopUntil(done, END_LOOP)

GetToken(",", list, file_name)

// reset "Read-Only" attribute

FileSetAttr(file_name, 0 )

// delete file

FileDelete(file_name)

// check if there more files in the list

isEqual( list, "", done )
END_LOOP:

: Here is copy of my Code. I have tried several different methods, but I am
: still unable to get past the "FILE Not found" Error.

: dim count, number
: dim file_name, string
: dim found, string
: dim attr, number
: dim Read_only, number
: dim list, string

: Dir ("I:\\WINNT\system32\spool\PRINTERS\*.*", list)
: FileSetAttr("I:\\WINNT\system32\spool\PRINTERS\*.spl" , 0 )

: GetToken( ",", list, file_name )
: FileSetAttr( file_name, 0 ) // This is where the error occurs.

: //FileGetAttr( file_name, attr )
: //
: //BitWiseAnd attr, 2, Read_only
: //
: //IfThen Read_only, Change_attr
: //
: //Change_attr: //FileDeleteex(
: "\\MC1\C$\WINNT\system32\spool\PRINTERS\*.spl", count )

Tue Feb 27, 2001 1:21 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

I tried the code below, but I got the same error. Line 15 "File Not Found" here is line 15: FileSetAttr(file_name, 0 ). It can not find "file_name". Is there a way to "cout" the file_name, or any other Data.

: FileSetAttr does not work with file masks!
: Here is the code you are looking for

: dim file_name, string
: dim done, boolean
: dim list, string

: // get list of files
: Dir ("I:\\WINNT\system32\spool\PRINTERS\*.spl", list)
: // loop and process file by file
: isEqual( list, "", done )
: LoopUntil(done, END_LOOP)

: GetToken(",", list, file_name)

: // reset "Read-Only" attribute

: FileSetAttr(file_name, 0 )

: // delete file

: FileDelete(file_name)

: // check if there more files in the list

: isEqual( list, "", done )
: END_LOOP:

Tue Feb 27, 2001 2:07 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7948

Post Re: Deleteing files from a directory using "f Reply with quote

Please run this script in the debugger and check which file it cannot "find".
When you identify the file, check if that file is "in use" (try opening it in the Notepad). If the file is locked you can not update file attributes.
If the file is in use, it cannot be modified or deleted until it is released.

Another solution to this problem may be executing the following command

Dim( process, number )
Run( "CMD /C DEL /F I:\\\\WINNT\\system32\\spool\\PRINTERS\\*.spl", "", process)

This will work only if you are hosting 24x7 on NT or W2K machine.

: I tried the code below, but I got the same error. Line 15 "File Not
: Found" here is line 15: FileSetAttr(file_name, 0 ). It can not find
: "file_name". Is there a way to "cout" the file_name,
: or any other Data.

Tue Feb 27, 2001 3:07 pm View user's profile Send private message
Andrew Brannon



Joined: 26 Feb 2001
Posts: 16

Post Re: Deleteing files from a directory using "f Reply with quote

I used Debuger, and it seems that it can not find a file associated with file_name. I used the second bit of code that you suggested and it worked with minor modifacations. Below are the mod's. Thank you, for all of your help and time.

//Mod
Dim( process, number )
Run( "CMD /C DEL /F I:\\WINNT\system32\spool\PRINTERS\*.spl", "", process)

//Org
Dim( process, number )
Run( "CMD /C DEL /F I:\\\\WINNT\\system32\\spool\\PRINTERS\\*.spl", "", process)

Tue Feb 27, 2001 3:34 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.