News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

I need a program called "FindLine"

Started by learn64bit, November 29, 2022, 04:41:33 AM

Previous topic - Next topic

sinsi

Assumption-that c.txt has a list of filenames, like 'e:\data\filename.ext'

from cmd.exe prompt
for /F "delims=" %i in (c.txt) do del "%i"

from batch file
for /F "delims=" %%i in (c.txt) do del "%%i"

Quote from: learn64bit on April 28, 2024, 08:59:10 AMbatch file can do tha? I don't think so.
:biggrin:

sudoku

Quote from: sinsi on April 28, 2024, 11:08:37 AMAssumption-that c.txt has a list of filenames, like 'e:\data\filename.ext'
...
from batch file
for /F "delims=" %%i in (c.txt) do del "%%i"
...
:biggrin:
Yeah, I had suggested a batch file too. But he wants something that can run from inside his 'findline' code.
:cool:

learn64bit

looks like delete file is easy.
how about delete empty folder? (maybe find the empty folder is difficult)
(after delete file, we need to delete all empty folders in c:\b)

learn64bit

Quote from: sinsi on April 28, 2024, 11:08:37 AMAssumption-that c.txt has a list of filenames, like 'e:\data\filename.ext'

from cmd.exe prompt
for /F "delims=" %i in (c.txt) do del "%i"

from batch file
for /F "delims=" %%i in (c.txt) do del "%%i"

Quote from: learn64bit on April 28, 2024, 08:59:10 AMbatch file can do tha? I don't think so.
:biggrin:

c.txt is 65001withoutBOM, is that ok?

learn64bit

Quote from: sudoku on April 28, 2024, 09:11:02 AMDo some research on API "DeleteFile"...

Later....
I made you a small example using "DeleteFile".

You first need to open the file that you want to delete, using CreateFile to verify that the file exists.
If it exists, close the handle returned by CreateFile.
Then call DeleteFile.

If the file that you want to delete does not exist, display an error message.

This is very basic code. The zip file contains two test files, to test deletion of those files.

Use caution using DeleteFile... it can be very dangerous, unless you know exactly what you are doing with it, and especially if you are going to run DeleteFile within untested code.

That being said, use at your own risk. I assume no responsibilty for misuse of this code, or accidentally deleted files. They (any accidentally deleted files) cannot be retreived from "Recycle Bin" after deletion. You have been warned.

    include \masm32\include\masm32rt.inc

    .data
        filename1  db "junktext1.txt", 0
        filename2  db "junktext2.txt", 0

    .code
    start:
        invoke CreateFile, addr filename1, 0, 0, 0, OPEN_EXISTING, 0, 0  ;;  to verify file exists
        cmp eax, -1
        jnz @f
        fn MessageBox, 0, "file not found", "file 1", 0    ;; display message if it doesn't exist.
        jmp nextfile
      @@:
        invoke CloseHandle, eax                            ;; close handle if file exists
        invoke DeleteFile, addr filename1                  ;; delete the file
      nextfile:

        invoke CreateFile, addr filename2, 0, 0, 0, OPEN_EXISTING, 0, 0  ;;  to verify file exists
        cmp eax, -1
        jnz @f
        fn MessageBox, 0, "file not found", "file 2", 0    ;; display message if it doesn't exist.
        jmp nomorefile
      @@:
        invoke CloseHandle, eax                            ;; close handle if file exists
        invoke DeleteFile, addr filename2                  ;; delete the file
      nomorefile:
     
        invoke ExitProcess, 0
       

    end start


code here and attachment revised. forgot to jump (after MessageBox call), if file not found

great.
maybe we should check if the "DeleteFile" failed.
(example: read-only, system-file, file-permission ...)

if failed, then inform user to deal with that

learn64bit

I think it will be two new apps: deleteFile and deleteEmptyFolder

deleteFile: input c.txt and c:\b
deleteEmptyFolder: input c:\b

jj2007

Under the hood it's DeleteFileW and RemoveDirectoryW:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Kill "somefolder\a.txt"  ; delete a file
  KillFolder "somefolder"  ; folder must be empty
EndOfCode


sudoku

Quote from: learn64bit on April 28, 2024, 08:56:31 PMI think it will be two new apps: deleteFile and deleteEmptyFolder

deleteFile: input c.txt and c:\b
deleteEmptyFolder: input c:\b
@learn64bit...
As jj said, DeleteFile can also delete empty folders. * see jj2007s post below this one.   Its early here and I havent had my coffee yet. :tongue:
I had forgotten that you also wanted to remove the folder as well. So did not put that in the example.

Quote from: learn64bit on April 28, 2024, 08:37:34 PMgreat.
maybe we should check if the "DeleteFile" failed.
(example: read-only, system-file, file-permission ...)

if failed, then inform user to deal with that
To check for whether or not DeleteFile succeeded or failed, that is a good idea.

In the example, I just looked to see if they were still there. I am lazy about those details.  :joking:
:cool:

jj2007

Quote from: sudoku on April 28, 2024, 11:42:32 PMAs jj said, DeleteFile can also delete empty folders.
Quote from: jj2007 on April 28, 2024, 10:29:01 PMUnder the hood it's DeleteFileW and RemoveDirectoryW:

sudoku

:cool:

learn64bit

SHFileOperationW is also good one for delete file

NoCforMe

Quote from: sudoku on April 29, 2024, 12:37:34 AMToo early in the morning for me to post.  :tongue:
OK, Sudoku, I'm challenging you:

You wrote that you understand what this guy's trying to do here. So would you please explain to us what this program is supposed to do and how it works (since he seems either unable or unwilling to do so)? And what the format of all these mysterious files (a, b, c, etc.) is and how that's supposed to work?

Thanks from all the perplexed readers here.
Assembly language programming should be fun. That's why I do it.

sudoku

Quote from: NoCforMe on April 29, 2024, 04:56:25 AMOK, Sudoku, I'm challenging you:
I will refer you to the OP, learn64bit. He can give a more precise answer than I could, it is his project after all. Or you could simply read through the thread.... there are breadcrumbs throughout, if you would care to look for them.
If anything that is not clear to you, you can ask learn64bit (as I have) as he is the author of this thread and the project.
There are commented source codes here (for some earlier versions) as well as example .txt files that demonstrate the use of the program. Also several versions of the executable, the more recent ones are the better of them.
:cool:

NoCforMe

So you don't know. Why didn't you just say so?
Assembly language programming should be fun. That's why I do it.

learn64bit