#138033 - 2005-04-15 10:23 AM
Find a file i multiple directorys
|
Kroppen
Fresh Scripter
Registered: 2005-03-11
Posts: 15
Loc: Västerås, Sweden
|
Hi,
Here's a newbe who wants help...
Here's the problem.. I want to find a file witch exists in several directorys on a drive. The output should be to a file witch I can use as input for a cleaning script that should delete the directorys where the file exists.
Is it possible to do it in another way, plz let me know?
Kroppen
|
|
Top
|
|
|
|
#138034 - 2005-04-15 11:01 AM
Re: Find a file i multiple directorys
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Hello Kroppen and welcome to the board.
Please take a look at all the various UDF scripts we have here. There are plenty of file and directory functions available.
UDF Mirror Sites - Sorted List of UDF
|
|
Top
|
|
|
|
#138035 - 2005-04-15 11:34 AM
Re: Find a file i multiple directorys
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
To get you started, you can get a simple list using the DOS DIR command: Code:
DIR /B /S c:\SOMEFILE.TXT >%TEMP%\FILELIST.TXT
This will find all instances of SOMEFILE.TXT on the C: drive, and write the list to a file called FILELIST.TXT in your TEMP directory.
|
|
Top
|
|
|
|
#138036 - 2005-04-15 11:57 AM
Re: Find a file i multiple directorys
|
Kroppen
Fresh Scripter
Registered: 2005-03-11
Posts: 15
Loc: Västerås, Sweden
|
Hi guys,
Thanks, now I'm on it...;)
This is how far I've got...
BREAK ON
$dir = "1"
WHILE $dir <> "" OPEN (1, "C:\2.TXT") $dir = READLINE (1) $Ascii = SUBSTR ($dir, 23, 14)
DEL "$Ascii\*.* /H /S" RD $Ascii LOOP CLOSE (1)
Regards..
|
|
Top
|
|
|
|
#138037 - 2005-04-15 12:17 PM
Re: Find a file i multiple directorys
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Good start.
Here is a method, with the search part included.
Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") Dim $sPath, $fdFileList, $sFileList Dim $sSearchPattern ; *** Change the search pattern to the name of the file you want to find *** $sSearchPattern="C:\rmt.exe" $sFileList=%TEMP%+"\FileList.txt" ; Create output list Shell '"'+%COMSPEC%+'" /C DIR /B/S "'+$sSearchPattern+'" >> "'+$sFileList+'"' If @ERROR "COULD NOT CREATE FILE LIST: "+@ERROR+" "+@SERROR+@CRLF Exit @ERROR EndIf ; Open file list for reading $fdFileList=FreeFileHandle() If Open($fdFileList,$sFileList) "COULD NOT OPEN FILE LIST FOR READING: "+@ERROR+" "+@SERROR+@CRLF Exit @ERROR EndIf ; Iterate entries $sPath=ReadLine($fdFileList) While Not @ERROR $sPath=Left($sPath,InStrRev($sPath,"\")-1) "Now deleting directory "+$sPath+@CRLF ; *** Do your delete stuff here *** $sPath=ReadLine($fdFileList) Loop $=Close($fdFileList) Exit 0
|
|
Top
|
|
|
|
#138038 - 2005-04-15 02:29 PM
Re: Find a file i multiple directorys
|
Kroppen
Fresh Scripter
Registered: 2005-03-11
Posts: 15
Loc: Västerås, Sweden
|
Thanks!! You've saved my day!
/Kroppen
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 641 anonymous users online.
|
|
|