0

I made a simple BATCH file for notes, it just deletes a folder, makes a new one, and puts in a file called note.txt and then edits it... for some reason, it doesn't do ANYTHING at all! not even removing the folder, here's the code:

goto start
:abort
        ECHO Aborted!
        PAUSE
        GOTO start

:replace
        del /q "D:\Users\Eldar\Desktop\Note Folder"
        mkdir "Note Folder"
        @echo>"D:\Users\Eldar\Desktop\Note Folder\note.txt"
        @echo %note%> "D:\Users\Eldar\Desktop\Note Folder\note.txt"
        pause

:start
    @ECHO OFF
    color e
    cls
    echo Put the note in here:
    set /p LastNote=<"D:\Users\Eldar\Desktop\Note Folder\note.txt"
    SET /P note=
    cls
    echo Note has been saved!
    echo also, the last note you saved was: "%LastNote%".
    echo so are you sure you want to replace this note with a new one (Y/N)?
    SET /P agree=
    IF "%agree%"=="y" (
         ECHO goto replace
    ) ELSE (
        GOTO abort
    )
2
  • Del is for files, use RD for directories/folders, type RD /? for help with that Commented Feb 6, 2017 at 18:26
  • Consider using the choice command for Yes/No questions. It does the input validation for you ;) Commented Feb 6, 2017 at 18:32

2 Answers 2

1

There are few errors in your script:

  1. del can delete only empty folders. Use rmdir /s /q folder_name to remove folder with files
  2. Remove ECHO in ECHO goto replace
  3. You are using full paths everywhere except mkdir. Is it correct?

My working version:

@echo off

goto start

:abort
    echo Aborted!
    pause
    goto start

:replace
    rmdir /s /q ".\TestF"
    mkdir "TestF"
    echo>".\TestF\note.txt"
    echo %note%> ".\TestF\note.txt"
    pause

:start
    color e
    cls
    echo Put the note in here:
    set /p LastNote=<".\TestF\note.txt"
    set /p note=
    cls
    echo Note has been saved!
    echo also, the last note you saved was: "%LastNote%".
    echo so are you sure you want to replace this note with a new one (Y/N)?
    set /p agree=
    if "%agree%"=="y" (
        goto replace
    ) else (
        goto abort
    )
Sign up to request clarification or add additional context in comments.

3 Comments

yes, the file is located at the same place the folder should be located in, that's why I do not use the path.
And the ECHO is a part of an attempt to copy a sample of IF from the network (I thought my IF statement is wrong) so I forgot to remove the ECHO because in the sample it had IF statement (ECHO FOUND)...
I know, I thought its the if, but it's not.
0

There appears to be no reason to remove the Note Folder directory or even to delete the note.txt file.

How does it perform if you rewrite it like this?

@Echo Off
Color 0E

Set "LastNote="
If Exist "%UserProfile%\Desktop\Note Folder\note.txt" (
    Set/P LastNote=<"%UserProfile%\Desktop\Note Folder\note.txt"
)
If Not Defined LastNote GoTo replace

:ask
    ClS
    Echo=The last note you saved was:
    Echo=%LastNote%
    Echo=
    Choice /M "Would you like to replace this note with a new one"
    If "%ErrorLevel%"=="1" GoTo replace
    Echo=
    Echo=Aborted!
    Timeout -1
    GoTo ask

:replace
    ClS
    Set/P "note=Put the note in here: "
    If "%note%"=="" GoTo ask
    Echo=Note has been saved!
    If Not Exist "%UserProfile%\Desktop\Note Folder\" (
        MD "%UserProfile%\Desktop\Note Folder"
    )
    (Echo=%note%)>"%UserProfile%\Desktop\Note Folder\note.txt"
    Timeout -1
    GoTo ask

For the benefit of the OP, here is your version of your script with the major flaws removed and with unnecessary lines kept in.

@goto start
:abort
    ECHO Aborted!
    PAUSE
    GOTO start

:replace
    rmdir "D:\Users\Eldar\Desktop\Note Folder"
    mkdir "D:\Users\Eldar\Desktop\Note Folder"
    echo.>"D:\Users\Eldar\Desktop\Note Folder\note.txt"
    >"D:\Users\Eldar\Desktop\Note Folder\note.txt" echo %note%
    pause

:start
    @ECHO OFF
    color e
    cls
    echo Put the note in here:
    set /p LastNote=<"D:\Users\Eldar\Desktop\Note Folder\note.txt"
    SET /P note=
    cls
    echo Note has been saved!
    echo also, the last note you saved was: "%LastNote%".
    echo so are you sure you want to replace this note with a new one (Y/N)?
    SET /P agree=
    IF "%agree%"=="y" (
        goto replace
    ) ELSE (
        GOTO abort
    )

7 Comments

The file doesn't need deleting because it is overwritten with the new content by default. :ask makes more sense than :start because it isn't at the start, change it back if you want. It's you asking for help and using terms such as wtf doesn't usually aid you in achieving that.
Well, I am too lazy to delete the file itself:3 Also, why do you SET "LastNote=" if then you set it again? I don't need this, I know it exists! I know there's something in the note... and omfg. Listen, I am not trying this code to be efficient, all I needed is it to work, I don't care if choice is a better idea or checking if the file exists or empty is better, because I know it exists and is not empty! Please don't try to "fix" or make things "better" because they're not, there's a reason I put it like this.
I asked for one tiny thing: Why is my file doesn't work? I didn't ask: "Hello can you help me make this more efficient?" All I asked is why doesn't it work, I got my answer, I don't need more than that!
The first time the script is ever run, there may be no existing note.txt or Note Folder. In that case there will be no data in %LastNote% and the script will then bypass the code asking about a replacement as there is nothing to replace. It's good coding practice, not an efficiency exercise. If you don't want good coding help go some place else, otherwise please be a little more respectful to those willing to help you.
I know how to code, but I also know what I am doing, this program was made for ME only, it will NEVER be published, therefore as I know myself, I will not leave an empty Note, and that's exactly why I am deleting and making a new folder. I do not need to check if the chances of a non-existing folder/file are 0%!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.