Checking if files exist

Help with writing and playing macros

Checking if files exist

Postby aclauson » Tue Jan 15, 2008 7:56 pm

Hi,

I'm new to UltraEdit, and I've searched the forums for this, but haven't found anything yet.

I have an index file of several million files and need to make sure that all of the files in the index actually exist. How can I loop through the entire file (over 2 million lines) and log to one text file when the file is found, but log to another text file when the file is not found?

File example:
\Folder\12345.fil
\Folder\12346.fil
\Folder\12348.fil
\Folder\12349.fil
\Folder\45\12345.fil
\Folder\45\12346.fil
\Folder\45\12349.fil
\Folder\45\12348.fil

Thanks!
User avatar
aclauson
Newbie
 
Posts: 1
Joined: Tue Jan 15, 2008 12:00 am

Re: Checking if files exist

Postby Mofi » Wed Jan 16, 2008 8:19 am

The following macro converts your list file into a batch file:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
TrimTrailingSpaces
Find RegExp "%^(*^)$"
Replace All "if exist "^1" echo ^1 >>_ExistingFiles.txt^pif not exist "^1" echo ^1 >>_MissingFiles.txt"
"@echo off
if exist _ExistingFiles.txt del _ExistingFiles.txt
if exist _MissingFiles.txt del _MissingFiles.txt
"
SaveAs "FileTest.bat"

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

Your example (file FileTest.bat) will look after macro execution as follows:

@echo off
if exist _ExistingFiles.txt del _ExistingFiles.txt
if exist _MissingFiles.txt del _MissingFiles.txt
if exist "\Folder\12345.fil" echo \Folder\12345.fil >>_ExistingFiles.txt
if not exist "\Folder\12345.fil" echo \Folder\12345.fil >>_MissingFiles.txt
if exist "\Folder\12346.fil" echo \Folder\12346.fil >>_ExistingFiles.txt
if not exist "\Folder\12346.fil" echo \Folder\12346.fil >>_MissingFiles.txt
if exist "\Folder\12348.fil" echo \Folder\12348.fil >>_ExistingFiles.txt
if not exist "\Folder\12348.fil" echo \Folder\12348.fil >>_MissingFiles.txt
if exist "\Folder\12349.fil" echo \Folder\12349.fil >>_ExistingFiles.txt
if not exist "\Folder\12349.fil" echo \Folder\12349.fil >>_MissingFiles.txt
if exist "\Folder\45\12345.fil" echo \Folder\45\12345.fil >>_ExistingFiles.txt
if not exist "\Folder\45\12345.fil" echo \Folder\45\12345.fil >>_MissingFiles.txt
if exist "\Folder\45\12346.fil" echo \Folder\45\12346.fil >>_ExistingFiles.txt
if not exist "\Folder\45\12346.fil" echo \Folder\45\12346.fil >>_MissingFiles.txt
if exist "\Folder\45\12349.fil" echo \Folder\45\12349.fil >>_ExistingFiles.txt
if not exist "\Folder\45\12349.fil" echo \Folder\45\12349.fil >>_MissingFiles.txt
if exist "\Folder\45\12348.fil" echo \Folder\45\12348.fil >>_ExistingFiles.txt
if not exist "\Folder\45\12348.fil" echo \Folder\45\12348.fil >>_MissingFiles.txt

Run now this batch file by double clicking on it in Windows Explorer or by using Advanced - DOS Command. You will get the 2 files _ExistingFiles.txt and _MissingFiles.txt after batch file execution. _MissingFiles.txt will not exist if there are no missing files.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4056
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros