![]() ![]() Windows 11 update brings Bing Chat into the taskbar Microsoft PowerToys 0.69.0: A breakdown of the new Registry Preview app For more info, visit our Terms of Use page. This may influence how and where their products appear on our site, but vendors cannot pay to influence the content of our reviews. We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships. No need to track down a third-party hard drive wipe utility. Not sure if this works but.How to perform a secure disk wipe with Windows 10’s Format command IF NOT EXIST *path here* GOTO NOWINDIRĭel *path here*/* /S /Q (dont copy this, the above prevents the del command from deleting everything in the folder, this is simallar to another answer.) I recommend you to take the whole code, if you don't want to take the whole code, then you can simplify this with. IF NOT EXIST C:\Users\%USERNAME%\%Point%\%d% GOTO NOWINDIR ![]() Your's should be like "path/to/folder" (no files!!) Set /P d=Which subdirectory? If you are putting multiple. If /I "%c%" EQU "Videos" set Point = "Videos" If /I "%c%" EQU "Pictures" set Point = "Pictures" If /I "%c%" EQU "Downloads" set Point = "Downloads" If /I "%c%" EQU "Documents" set Point = "Documents" If /I "%c%" EQU "Desktop" set Point = "Desktop" If you wanted to empty the folder, my take is: OFF (If you like, you can comment the script with the above descriptions using rem or .) Finally, it uses popd to return to the previously-current directory and ends the script.Because it doesn't try to remove the target directory until after its contents have been removed, it should now be empty (other than anything that also has open file handles).Because the target directory is the current directory, the system has an open file-handle to it, and thus it cannot actually delete it, so it remains as is, which is the desired behavior.It then uses rd to delete the target directory and all of its contents, redirecting any errors (which there should be at least one for the directory itself) to nul.It's a slight inconvenience to have to use the non-short filename, but it's better safe than sorry, especially since SFNs aren't completely reliable or always predictable (and may even be disabled altogether). C:\Users\Bob Bobson\foobar won't be seen as being the same as C:\Users\BobBob~1\foobar even if they actually are). It doesn't work with short-filenames (e.g.This check is case-insensitive, so it's usually safe on Windows, but isn't for any case-sensitive file-systems like those used by *nix systems, even under Windows.This avoids accidentally deleting the contents of the previous directory if the pushd command failed (e.g., passing an invalid directory, access-error, etc.) It checks to see if the current directory is now the same as the target directory, and prints an error message and quits if it is not.It uses pushd to save the current directory, then switch to the target directory, redirecting any errors to nul for a cleaner command-line experience (and cleaner logs).It checks if a command-line argument has been passed, and prints usage information and quits if not.If /i not = goto wrongdirĮcho Delete all of the contents of a directoryĮcho %0 is a substitute for deltree, it recursively deletes the contentsĮcho (files and folders) of a directory, but not the directory itselfĮcho DIR is the directory whose contents are to be deletedĮcho Could not change to the target directory. bat ?): :: dt is a Windows-compatible version of the deltree command It's also as safe as can be, with error-checking everywhere possible, and also as user-friendly as possible, with built-in docs.ĭt.bat (or dt.cmd for the kids whatever, I'm old, I use. It doesn't set any environment variables and it doesn't use any loops. It's probably about as simple and efficient as is possible with a command-line script instead of outright writing an actual executable. Here's a solution that works without resorting to third-party tools. The deltree command could do this, but Micrsoft, in its infinite "wisdom" removed the command and didn't port it to Windows. To be clear, rd /s /q c:\foobar deletes the target directory in addition to its contents, but you don't always want to delete the directory itself, sometimes you just want to delete its contents and leave the directory alone. User340956 was painfully close to the solution, but you know what they say about close… ![]()
0 Comments
Leave a Reply. |