20. August 2018 · Comments Off on Fast Delete Complex Directories · Categories: Batch Files, Command-line Tools, Windows
Last updated on 03/02/2024

Normally, deleting directories is fairly quick if they contain a modest number of sub-directories and files. But when directories have complex structures, consisting of hundreds or thousands of sub-directories and files, it may take several minutes or even hours to delete them. The command line, with less overhead, can delete complex directories in a fraction of that time, sometimes quoted as being 20 times or more faster than the traditional explorer option. This guide demonstrates how to automate deleting large directories using batch files or directly from the command line using native Windows commands and tools, and with selected freeware GUI deletion programs that include a command line option. An additional section tests and compares the deletion speeds of the various deletion tools covered in this guide.The emphasis of this guide is on the quick deletion methods and not on secure or permanent deletion methods that are used to make files unrecoverable. Secure deletion methods are another topic and are necessarily slower since they involve overwriting files, often using several passes.

delete

Explorer can be extremely slow when deleting directories because it calculates the folder size, the number of items in the folder, and the estimated completion time before processing, and reports on the items deleted, remaining deletions, current deletions, and while monitoring and reporting on any conflicts during processing. These processes are still in effect even when the recycle bin is emptied or when files and folders are deleted directly using Shift+Del. Using the command line eliminates this overhead, resulting in a faster deletion process. Keep in mind that faster means relative to the standard deletion process, so deleting several Gigabytes of files and directories may still take a significant amount of time. For example, tests performed by a SuperUser member found that it took an average of 53 minutes to delete 28.3 GB consisting of 1,159,211 files in 146,918 folders using the fastest command line method tested (a combination of the DEL and RMDIR commands). If files and folders are to be deleted on a regular basis, probably the fastest method is to save them to a dedicated partition and then format that partition to delete everything.

Commands

Although the RMDIR command can remove a directory and its files, it’s significantly slower than using the DEL and RMDIR commands in a two-step process. The DEL command deletes the files, and the RMDIR command deletes the directory structure.

del /f/q/s "%folder%" >nul

Acts as a first pass to delete files and outputs to nul to avoid the overhead of writing to the screen

rmdir /q/s "%folder%"

2nd pass that removes the directory structure

  • /f – Force delete read-only files
  • /q – Quiet mode, do not ask to delete
  • /s – Include subdirectories

RoboCopy

Another method for deleting folder files is RoboCopy. A destination folder is mirrored from an empty source directory, which forces RoboCopy to delete any files not in the source directory.

The main command for RoboCopy to delete all files in the destination directory:

robocopy "EmptyDir" "DestinationDir" /MIR /ETA

  • /MIR – Mirror a directory
  • /W:0 – Sets wait time between retries to zero secs
  • /R:0 – Sets number of retries on failed copies to zero secs

RoboCopy works with directories and sets of files within directories as opposed to individual files. In the example batch files using RoboCopy, RMDIR is still used to remove the temporary empty directory and the parent destination directory, and DEL is used for deleting files.

Using Batch Files

Batch files, including the example files below, may be used from the command line (with parameters), from the send-to directory, the right-click context menu, or by drag and drop (the easiest method).

Command line

The batch files may be executed from a Windows command prompt with parameters, or added to the environmental path for convenience.

To execute from a command prompt, open a new cmd prompt, navigate to the batch file’s location and enter its full name, or enter the batch file’s full path. Be sure to add the directories and/or files to delete as parameters. Also include quotes around any file paths with spaces:

Ex. “C:\Program Files\delete_file_folder_fast_simple_v2.bat” “C:\Folder or file to delete”

Separate multiple parameters with a space between parameters.

Adding a batch file’s folder to the Windows environment variable allows it to be available from any cmd prompt without navigating to the batch file’s location or typing its full path. To add a batch file’s path to the Windows environment use:

start–> Control Panel–> System–> Advanced system settings–> Advanced Tab–> Environment Variables–> System Variables–> Path–> Edit.

Add the path e.g., ;C:\path to the batchfile; to the end (don’t forget the single semicolons at the beginning and end). Hit OK three times.

Right-click Context Menu

This option allows the user to right-click a folder and select the batch file from the pop-up menu. The steps to enable this are:

  1. Press the WINDOWS KEY + R to open the Run dialog box
  2. Enter regedit and press ENTER
  3. Navigate to HKEY_CLASSES_ROOT\Directory\shell\
  4. Right-click on the yellow shell key. Select New > Key
  5. Enter a name: Delete &Fast then press ENTER
  6. Right-click on the Delete &Fast folder created, and select New > Key
  7. Enter “command” and press ENTER.
  8. Left-click on the yellow command key created. Double-click the (Default) entry.
  9. In the Value Data field, enter the batch file to use, e.g., cmd /c \”C:\\Path to\\delete_file_folder_fast_simple_v2.bat\” %1″ then press OK

Another way to accomplish the above is to use a reg file. Copy the code below, paste it into a file editor and save it as “Delete Fast.reg”. Double click the file to merge its contents to the registry and the right-click menu is ready to use.


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Delete &Fast\command]
@="cmd /c \"C:\\Path to\\delete_file_folder_fast_simple_v2.bat\" %1"

Send to Directory

Another option is the Send to directory, Just create a shortcut and add it to the appropriate directory:

For newer versions of Windows, the send to directory is located at:

C:\Users\<yourusername>\AppData\Roaming\Microsoft\Windows\SendTo

For XP, the location is:

C:\Documents and Settings\<yourusername>\SendTo

To use, right click a file or directory and select the batch file from the Send to menu.

Drag and Drop

The easiest way to use the example batch files is to just drag and drop folders or files onto them. No files or folders will be deleted without user confirmation.

Differences in the Example Batch Files

delete_files_folders_fast_v2.bat – lists multiple files and folders to be deleted, the parent directory, limited folder/file attributes, and limited information on the names and numbers of files and folders deleted. Also includes a delayed exit, allowing the files and folders deletion information to be reviewed before the window closes (default 10 seconds).

delete_file_folder_fast_simple_v2.bat – limited to deleting one file or one folder at a time. Doesn’t provide much interaction or feedback except to ask  the user if they actually want to delete the displayed file or folder. Automatically exits after deleting the file or folder.

delete_files_folders_fast_robocopy_v3.bat – essentially the same as delete_file_folder_fast_simple_v2.bat except that RoboCopy’s output is displayed during execution and after processing files. The batch file is paused after execution allowing the user to view the results without automatically exiting. Updated 01-29-20.

delete_files_folders_fast_robocopy_silent_v3.bat – essentially the same as above except that RoboCopy’s output is NOT displayed for faster execution and processing. The batch file automatically exits after a delay of 10 seconds. Added 01-29-20.

delete_file_folder_fast_simple_robocopy_v2.bat – limited to deleting one file or one folder at a time.Uses RoboCopy instead of DEL for deleting folder contents. RoboCopy output is redirected to nul to eliminate command output. Automatically exits after deleting the file or folder.

delete_file_folder_fast_byenow_v1.bat – uses command line program byenow to delete a folder and all of its files and subdirectories.Uses byenow’s default settings. Batch file pauses on completion.

delete_file_folder_fast_byenow_ntapi_v1.bat – uses command line program byenow to delete a folder and all of its files and subdirectories. Same as previous batch file but uses –delete-ntapi option. Batch file pauses on completion.

The batch files may be renamed and will work identically.

Example Batch Files using DEL, RMDIR, and RoboCopy

Left-click to view the file in the current window, or use right-click and “Save Link As” to download.The batch files are changed from the previous versions as the /S switch greatly slowed performance when deleting individual files. The /S switch is still used, but only for folders.
Note: Remove the “.txt” extension before using.

The batch files below use only the RMDIR and DEL commands.

  delete_files_folders_fast_v2.bat (4.0 KiB, 3,255 hits)

  delete_file_folder_fast_simple_v2.bat (1.2 KiB, 2,050 hits)

The below batch files use RoboCopy to delete folder files, RMDIR to delete  empty folders, and DEL to delete individual files. If RoboCopy is installed but not included in the Windows environment path, be sure to change the path for RoboCopy for your system in the batch file (don’t forget to remove the REM to enable it). No changes to the batch files are required if RoboCopy is already installed and included in the path. To check, type “robocopy: in a command prompt. If RoboCopy executes, it’s already installed and included in the environment path.

  delete_files_folders_fast_robocopy_v3.bat (4.6 KiB, 2,265 hits)

  delete_files_folders_fast_robocopy_silent_v3.bat (5.1 KiB, 2,051 hits)

  delete_file_folder_fast_simple_robocopy_v2.bat (1.7 KiB, 2,381 hits)

Freeware Deletion Tools

A number of GUI and command line file and folder deletion tools are available, but most focus on secure deletions and don’t provide an option for standard deletions. The freeware utilities below are able to perform both standard and secure deletions from the GUI and from the command line.

These GUI-based tools work from the command line either through the main executable for by using separate command line executables. The advantage of using these tools rather than using native windows commands like RMDIR and DEL is that it’s easier to configure complex deletion options such as deleting files or folders based on modification or creation date, size, or type, as well as to write logs, send the process to background, set automatic system shutdowns, exclude/include specific files and folders, stop on errors, and set many other options using  a single command line.

FastCopy

FastCopy is a copy/backup utility that can also perform standard and limited secure deletions on individual files and folders. It can be installed as a regular program or as a portable application by selecting extract during installation. The program executable also accepts commands from the command line.

Files and folders can be dropped and dragged onto the interface to set the source or destination directories. From the Options menu, the program can be configured to install shell extensions to enable FastCopy to delete, copy, or move files/folders by using the right click menu in Windows Explorer.

FastCopy Main Interface

FastCopy Interface

FastCopy Delete Options

FastCopy Delete Options

FastCopy Shell Extension Options

FastCopy Shell Extension Options

FastCopy Command line and Batch File

A listing of FastCopy’s command line options can be found online help page and in the application’s help file. The below batch file is configured to delete files and folders using drag and drop with two options: (1) Do NOT ask for confirmation before deleting and disable logging, and (2) Ask for confirmation before deleting and enable logging. The batch file pauses after execution. The batch file is configured to use a portable installation.

The breakdown of the first FastCopy command line (no confirmation, no logging):

FastCopy.exe /cmd=delete /no_confirm_del /log=FALSE /auto_close %*

  • /cmd=delete – delete command
  • /no_confirm_del – Don’t confirm before deleting
  • /log=FALSE – Disable write operation/errors information to the logfile
  • /auto_close – Close automatically after execution is finished with no errors
  • %* – All dragged and dropped files and folders

Example Batch File for FastCopy (remove .txt extension before using):

  Fastcopy_delete_file_folders_v1.bat (1.7 KiB, 1,575 hits)

Fast Folder Eraser Pro

Fast Folder Eraser Pro is an installed freeware program. It can perform both standard and secure deletions both from the command line or from the GUI interface. The standalone command line executables are located in the command-line folder which contains two CLI executables, a 32-bit version and a 64-bit version.

This is a utility specifically designed to delete directories and the sub-folders and files within them. Unlike FastCopy, it’s unable to delete individual files by filename, but it’s able to delete individual or groups of files based on size, dates, and other filters, and it can exclude files using wildcards. Although folders and files can be directly dragged and dropped onto the GUI interface for deletion, testing revealed that when a file was dropped on the GUI, the program also deleted every other file and folder within the same directory as the dropped file. There were no issues with folders dropped onto the GUI or deleted using the CLI executable. The CLI executable is unable to delete individual files and generates an error if an individual file path is used with the delete command.

Compared to FastCopy, the number of command line options is limited. For example, no option exists to enable or disable confirmation before deleting a file, so a confirmation option must be programmed into the batch script using Windows commands to obtain this functionality.

 

Fast Folder Eraser Pro Interface

Fast Folder Eraser Pro Interface

Fast Folder Eraser Pro Delete Options

Fast Folder Eraser Pro Delete Options

Fast Folder Eraser Pro Command line and Batch File

The help file for the standalone CLI executables is located in the command-line folder along with two executables, a 32-bit CLI executable, FFECmd32.exe, and a 64-bit executable, FFECmd64.exe. The batch file below is configured for drag and drop using the 32-bit executable, includes confirmation before deletion, and pauses after execution.. Unlike FastCopy where multiple files and folders can be processed using a single command, the CLI executable in Fast Folder Eraser Pro is able to process only a singe folder at a time. If multiple folders are dragged and dropped onto the batch file, folders after the first are ignored. If a file or multiple files are dropped onto the batch file, the files are not processed.

The breakdown of the Fast Folder Eraser Pro command line as used in the batch file:

FFECmd32.exe /path %* /r /logfail

  • /path %* – absolute path of directory to initiate deletion
  • /r – recurse child directories
  • /logfail – log unsuccessful file deletions to a log file

Example Batch File for Fast Folder Eraser Pro (remove .txt extension before using):

  FastFolderEraserPro_delete_file_folders.bat (903 bytes, 1,461 hits)

byenow Command Line Utility

byenow is a specialized command line tool specifically designed to delete files and directories under a single folder. It uses several strategies not found for other deletion tools to streamline and optimize the deletion process such as: (1) providing essential, but not verbose, processing information, (2) the option to suppress confirmation, (3) using all available CPU cores by default, and (4) the option to use the NtDeleteFile API instead of the standard deletion process (DeleteFile API) to delete files. The NtDeleteFile API is faster because it requires only a single syscall instead of the three syscalls needed by the standard DeleteFile API. byenow also displays the time required for the deletion process upon completion. Below is a summary listing of byenow’s user settable options:

  • preview the number files and folders to be deleted
  • set the number of threads (uses same number of threads as CPU cores by default)
  • suppress confirmation
  • list errors
  • display progress on a single line
  • staged deletion – scan folder 1st and then delete
  • use NtDeleteFile API instead of the default DeleteFile API
byenow options

byenow Options

byenow preview mode

byenow Preview

byenow Command line and Batch File

Because byenow is already optimized for file deletion using its default settings, and its options are settable from the command line, only a basic batch file is needed to launch the program in a command window. Two batch files are provided, one with default settings and the other using the NtDeleteFile API. Because byenow is a command line only program, be sure to set the path for byenow in the batch files.

The breakdown of the byenow command line (with NtDeleteFile API option):

byenow “%~1” –delete-ntapi

  • –delete-ntapi – use NtDeleteFile API instead of DeleteFile API

Example Batch Files for byenow (remove .txt extension before using):

  delete_files_folders_fast_byenow_v1.bat (1.6 KiB, 1,609 hits)

  delete_files_folders_fast_byenow_ntapi_v1.bat (1.6 KiB, 1,492 hits)

Batch File Benchmarks

The batch files were compared by benchmarking them using the standard Windows deletion process as a baseline. Nine identical test directories were created, each comprised of 12255 files in 1599 directories, and totaling 1658MBs. Each batch file was timed using a timer and/or using the logged times where appropriate to measure how long it took them to delete the test directory.

Batch fileResults (min:secs)
delete_file_folder_fast_simple_robocopy_v2.bat0:26
delete_files_folders_fast_byenow_v1.bat0:27
delete_files_folders_fast_robocopy_silent_v3.bat0:31
delete_file_folder_fast_simple_v2.bat0:32
delete_files_folders_fast_byenow_ntapi_v1.bat0:33
delete_files_folders_fast_v2.bat0:34
Fastcopy_delete_file_folders_v1.bat (confirm)0:37
Fastcopy_delete_file_folders_v1.bat (no confirm)0:40
FastFolderEraserPro_delete_file_folders.bat0:44
delete_files_folders_fast_robocopy_v3.bat0:49
Windows Standard Deletion to Recycle Bin*1:57

*Time includes 0:40 secs to send the test directory to the Recycle Bin and 1 min and 17 secs to empty the Recycle Bin (0:40 + 1:17 = 1:57).

Conclusions

Most of the command line tools tested were faster than using Windows standard delete, especially when the time needed to empty the Recycle Bin was included. The fastest command line tools were nearly twice as fast as the Windows standard delete process that sends files to the Recycle Bin, and over 4 times faster than Windows when the time needed to empty the Recycle Bin was factored in. Suppressing output and disabling logging helped to improve the performance of the command line tools, but the most significant factor appears to be that all the command line tools directly delete files and don’t use the Recycle Bin. The tests suggest that any program that directly deletes files will automatically seem faster in comparison to the full Windows standard delete process, even when they are actually slower than the time Windows takes just to send deleted files to the Recycle Bin. So while command line tools are  faster than using Windows Explorer for deleting large directories and files, It appears that claims of increased deletion speeds by multiple factors are likely exaggerated, and a more realistic expectation is probably from 2-3 times faster – at least for the freeware tools tested.

The test machine used was a 1.86GHz 32-bit single core laptop with 2GB of RAM. Some of the programs, such as byenow, are designed to take advantage of multiple cores, so results could vary greatly depending on the hardware and OS used. Also, the test directories were not really representative of a “real world” situation as they were actually small, and most users are unlikely to use specialized deletion tools to occasionally delete directories of less than 3-4 GBs. Although useful as a “rough estimate”, a more realistic test scenario might be to test the various batch file commands on machines with upgraded OS and hardware, and using a larger and more complex directory structure of perhaps 50 GBs or more .

Summary of test limitations:
Test on multiple hardware and OS platforms
Use larger and more complex test directories
Test multiple times to compensate for machine state variation

Related Information and References:

Fastest Way to Delete Large Folders in WindowsMatt’s Repository

How to delete huge number of files on WindowsSuperuser

Print Friendly, PDF & Email
Share
19. October 2017 · Comments Off on Automate Downloading Web Images to any Folder · Categories: AutoHotKey, Graphics, Scripts · Tags: AutoHotKey, Command-line Tools, Windows
Last updated on 05/12/2020

Automate saving web images to a specified folder by copying image URLs to the clipboard using an AutoHotKey (AHK) script. Usually, the process to save a web image from a browser consists of: (1) right-click the image, (2) select “save picture as”, and (3) navigate to the folder to save the image. While usually acceptable for single images, this process can can be slow and tedious for multiple images.

folder and images

AutoHotKey and Wget need to be installed for the script to work. The version of Wget used for this guide was wget-1.19.1_curl-7.52.1_win32_win64.7z, a portable package with Curl that includes the 32-bit and 64-bit versions of Wget, a ca certificate, localization, and a manual. The latest Wget windows binaries may also be downloaded from eternallybored.org.

The script was tested on a 32-bit version of Windows XP, using portable versions of AutoHotKey and Wget. The only modification needed for a portable installation of Wget is to set the path for the wget or wget64 executables in the script. The script will work without modification if Wget and AutoHotKey are already installed and the paths for AHK and Wget were set by the installer. Paths can be checked with the “set” command from a windows prompt, or by using Control Panel -> System -> Advanced Tab -> Environment Variables -> System Variables -> Path.

AHK Script Download

(Click to view, or right-click and use “save Link Target as” to download):

  wget photos cects.txt (3.1 KiB, 2,461 hits)

Setup and Use:

Setup
Before using, enter the path to the wget or wget64 executable in the script if wget is not in the system path. Optionally, enter a full path to an icon file for the script. Also, the extension of the script must be changed from txt to ahk.

How to Use

  1. Start the script with a double-click
  2. Enter or paste an existing folder path to save downloaded images and click OK. If no path is entered the default path will be the same folder as the script.
  3. Right click an image in your web browser and select “Copy image URL”
    1. A cmd window opens and displays downloading progress. It closes after the download is completed
    2. The image URL and date are appended to photolog.csv in the specified folder
    3. All characters after jpg. jpeg, gif, or png are removed from the URL before downloading
    4. URLs that don’t include the jpg, jpeg, gif, or png extensions are ignored
  4. To change folders, reload the script and enter a new existing folder path

Context menu tools such as FilemenuTools may be used to start the script and set the download folder automatically from any location.

Print Friendly, PDF & Email
Share
24. September 2017 · Comments Off on How to find Created, Published and Modified Dates for a Web Page · Categories: Web · Tags: Internet
Last updated on 04/26/2022

Finding the created, published or last modified date for web pages isn’t always as straightforward as it might appear. Although there are several ways to find the dates of web pages, none are 100% reliable, because regardless of the method used, no standard exists for dating web pages. The most authoritative way to find dates is from the page content itself, and even that has its shortcomings, since nothing requires dates to be accurate in the first place. In most cases, the best that can be achieved will be an approximation.

calender

Some of the methods that can be used to find created, published, or modified dates for web pages are:

  1. Web page content
  2. HTTP Headers
  3. Browser Plugins
  4. Javascript in Address Bar
  5. The Wayback Machine
  6. Google Cache
  7. RSS Feed

1. Web Page Content (preferred method when possible)

Pages often have a first published, updated, or posted date somewhere on the page. As mentioned, although this is the most accurate method, it still has its problems. An author could leave the date out, or use a wrong date – either intentionally or unintentionally. Even so, obtaining dates from web page content is the most accurate and authoritative method.

2. HTTP Headers

The Last-Modified field is an optional response field that reflects the date the origin server believes that the resource was modified. Because it is an optional field, it may or may not exist. Also, because no standard exists as to what the Last-Modified date field means, it’s often inaccurate or incorrect since that field also reflects any alterations made to the page, such as user comments or any changes other than the content.

3. Browser Plugins

There are browser plugins that can read a web page’s Last-Modified date field, but this method is still subject to the problems described for HTTP Headers above.

4. Javascript in Address Bar

This is a quick and easy way to retrieve the date from the site’s Last-Modifed date field in the HTTP Headers. To use it, just copy and paste the JavaScript string below to the address bar, or save it to a bookmark on your browser’s bookmark bar:

javascript:alert(document.lastModified)

Note: With dynamically generated content this will not work. Also, newer Internet browsers with an Omnibox require the user to manually type in javascript: even after they paste the entire string.

5. The Wayback Machine

The Way Back Machine was created by the nonprofit organization, the Internet Archive. It archives sites from the World Wide Web and other Internet information. There are a number of limitations to using this method including:

  • not all pages on a site may be included
  • not all sites are included. Webmasters can request that they not be included
  • often it doesn’t include all changes made to web sites
  • it may not be up-to-date. It can take several months for pages to appear
  • user-defined dates cannot be specified, but only dates crawled by the Way Back Machine’s web crawler

6. Google Cache

Google Cache displays a web page when it was last crawled by Google. There are several problems with this method including:

  • there isn’t a way to know the last time a page was crawled
  • it isn’t possible to specify a date range of the cache
  • changes to web sites are not tracked

To use Google Cache, enter the following into your web browser’s address bar, changing the name at the end of the URL to the site in question:

https://webcache.googleusercontent.com/search?q=cache:https://www.NameOfWebsite.com

7. RSS Feed

Many, but not all, sites include a RSS feed. If so, the published date for the page may be contained within its XML file. RSS XML files could have any name, but often use names such as index.xml or feed.xml. If it exists, it may be possible to view the file in a web browser to find dates. For further information, see Opening XML Files with a Browser. A simpler and easier option is to view the RSS feed for the page using a RSS feed reader.

Conclusion

If possible, the most authoritative and reliable method for finding the created, published, or modified dates is from the web page content. If dates don’t exist in the content, one or a combination of the above methods can be used to obtain approximate dates.

References:

Determine last modified date of a web page – Computer Hope

How do I find out when a web page was written? – Ask Leo

How to find out when a web page was created or updated – Maxi-Pedia

How to Know When a Web Page was Last Modified? – Infopackets

 

 

Print Friendly, PDF & Email
Share
25. May 2017 · Comments Off on FFMPEG Command-line and Video Format Reference · Categories: Command-line Tools, TechBits, Video · Tags: ffmpeg
Last updated on 01/19/2020

clker.com
A handy reference source that provides FFMPEG command-line examples with breakdown as well as general information about video formats.

BugCodeMaster

 
Print Friendly, PDF & Email
Share
23. March 2017 · Comments Off on Unable to Open or Rename File with Long File Name · Categories: TechBits · Tags: File Managment
Last updated on 12/11/2017

file

Use 7-Zip

  1. Open the 7-Zip file manager
  2. Go to the folder of the long name file
  3. Select the file, right click on it and select “rename”
  4. Erase some of the words of the file and press enter

 

h/t ax_Cap

Source: TechPowerUp Forums

 

Print Friendly, PDF & Email
Share
tour blog
">Bear

Bad Behavior has blocked 2169 access attempts in the last 7 days.

notice