• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Files disappeared into Limbo with .bat file

MemeMaestro

New Coder
So the thing is, I built myself a .bat file to clean up my entire desktop with one click. I then executed said file and was dumb enough to immediately do so on the desktop rather than testing it in a seperate folder first. Then, as the title suggested, disaster struck and while the folder was created correctly, it ended up empty and all my files are gone and I don't know where they went. I am hoping that someone may be able to tell me where they are, help me get them back, or just deliver the bad news that they're lost in Limbo forever.

Here's the code in question:

Code:
@echo off

set "data_folder=%UserProfile%\Desktop\DATA"

if not exist "%data_folder%" (
    mkdir "%data_folder%"
) else (
    echo Ordner %data_folder% existiert bereits.
)

for %%A in ("%UserProfile%\Desktop*") do (
    if not "%%~xA"=="" (
        set "type_folder=%data_folder%%%~xA"
        if not exist "%type_folder%" mkdir "%type_folder%"
        move "%%~A" "%type_folder%"
    )
)

echo Done!
pause

Note that I have since fixed the code and it is now working as intended. Though my files are still lost.
 
The code shown here does not delete any files. I guess in your original bat file you used the DEL command ? Then the files have been permanently deleted, as the DOS command line does not use the Recycle Bin. But of course you have a backup so all should be ok, right ?

Note that deleting a file only deletes the file headers (the names, so to speak), not the file contents. You might be able to recover them using one of the several available undelete utilities. But you need to be quick, before any of the freed disk space (still containing the old data) is going to be reused by new files.

This reminds me of the day I created a handy UNIX script that would loop through a directory, for each file asking whether to delete it or not. I tested it on my user directory, duly answering NO for each file. After the script finished, I found to my dismay that all the files were gone. Turned out I had the yes/no test programmed the other way round 😮 I don't remember if I got them back and how, it was a long time ago.
 
The code shown here does not delete any files. I guess in your original bat file you used the DEL command ? Then the files have been permanently deleted, as the DOS command line does not use the Recycle Bin. But of course you have a backup so all should be ok, right ?

Note that deleting a file only deletes the file headers (the names, so to speak), not the file contents. You might be able to recover them using one of the several available undelete utilities. But you need to be quick, before any of the freed disk space (still containing the old data) is going to be reused by new files.
I didn't use the Del command. The code seen is the code I exectued when the files disappeared.

I'll try the undelete idea tomorrow regardless and perhaps let you know how it went :)
 
I didn't use the Del command. The code seen is the code I exectued when the files disappeared.

I'll try the undelete idea tomorrow regardless and perhaps let you know how it went :)
Oh right. Then it looks you have been renaming each file to the same name, which is nearly as good as deleting them all.
I have to say I've no actual experience with undelete utilities... I prefer making regular backups (which I hope you'll start to do from now on too).
Do let know how you fare with an undelete program. I wouldn't hold my breath though.
 

New Threads

Latest posts

Buy us a coffee!

300x250
Top Bottom