user6929395 user6929395 - 1 month ago 9
Python Question

How do I add mass comments into Windows Command prompt?

I have a lot of text I would like to add as a comment. For example, I want to put the enitre help section of CHKDSK:


Checks a disk and displays a status report.


CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]] [/B] [/scan] [/spotfix]


volume Specifies the drive letter (followed by a colon),
mount point, or volume name.
filename FAT/FAT32 only: Specifies the files to check for
fragmentation.
/F Fixes errors on the disk.
/V On FAT/FAT32: Displays the full path and name of every
file on the disk.
On NTFS: Displays cleanup messages if any.
/R Locates bad sectors and recovers readable information
(implies /F, when /scan not specified).
/L:size NTFS only: Changes the log file size to the specified
number of kilobytes. If size is not specified, displays
current size.
/X Forces the volume to dismount first if necessary.
All opened handles to the volume would then be invalid
(implies /F).
/I NTFS only: Performs a less vigorous check of index
entries.
/C NTFS only: Skips checking of cycles within the folder
structure.
/B NTFS only: Re-evaluates bad clusters on the volume
(implies /R)
/scan NTFS only: Runs a online scan on the volume
/forceofflinefix NTFS only: (Must be used with "/scan")
Bypass all online repair; all defects found
are queued for offline repair (i.e. "chkdsk /spotfix").
/perf NTFS only: (Must be used with "/scan")
Uses more system resources to complete a scan as fast as
possible. This may have a negative performance impact on
other tasks running on the system.
/spotfix NTFS only: Runs spot fixing on the volume
/sdcleanup NTFS only: Garbage collect unneeded security descriptor
data (implies /F).
/offlinescanandfix Runs an offline scan and fix on the volume.
/freeorphanedchains FAT/FAT32/exFAT only: Frees any orphaned cluster chains
instead of recovering their contents.
/markclean FAT/FAT32/exFAT only: Marks the volume clean if no
corruption was detected, even if /F was not specified.

The /I or /C switch reduces the amount of time required to run Chkdsk by
skipping certain checks of the volume.


However, it is very annoying (and time-consuming) to have to put
rem
tags on the front of every line of code, like:


rem Checks a disk and displays a status report.


rem CHKDSK [volume[[path]filename]]] [/F] [/V] [/R] [/X] [/I] [/C] [/L[:size]] [/B] [/scan] [/spotfix]


rem volume Specifies the drive letter (followed by a colon),
rem mount point, or volume name.
rem filename FAT/FAT32 only: Specifies the files to check for
rem fragmentation.
rem /F Fixes errors on the disk.
rem /V On FAT/FAT32: Displays the full path and name of every
rem file on the disk.
rem On NTFS: Displays cleanup messages if any.
rem /R Locates bad sectors and recovers readable information
rem (implies /F, when /scan not specified).
rem /L:size NTFS only: Changes the log file size to the specified
rem number of kilobytes. If size is not specified, displays
rem current size.
rem /X Forces the volume to dismount first if necessary.
rem All opened handles to the volume would then be invalid
rem (implies /F).
rem /I NTFS only: Performs a less vigorous check of index
rem entries.
rem /C NTFS only: Skips checking of cycles within the folder
rem structure.
rem /B NTFS only: Re-evaluates bad clusters on the volume
rem (implies /R)
rem /scan NTFS only: Runs a online scan on the volume
rem /forceofflinefix NTFS only: (Must be used with "/scan")
rem Bypass all online repair; all defects found
rem are queued for offline repair (i.e. "chkdsk /spotfix").
rem /perf NTFS only: (Must be used with "/scan")
rem Uses more system resources to complete a scan as fast as
rem possible. This may have a negative performance impact on
rem other tasks running on the system.
rem /spotfix NTFS only: Runs spot fixing on the volume
rem /sdcleanup NTFS only: Garbage collect unneeded security descriptor
rem data (implies /F).
rem /offlinescanandfix Runs an offline scan and fix on the volume.
rem /freeorphanedchains FAT/FAT32/exFAT only: Frees any orphaned cluster chains
rem instead of recovering their contents.
rem /markclean FAT/FAT32/exFAT only: Marks the volume clean if no
rem corruption was detected, even if /F was not specified.

rem The /I or /C switch reduces the amount of time required to run Chkdsk by
rem skipping certain checks of the volume.


Is there a way I could mass comment code (like
""" comment here, can be multiple lines"""
in Python?)

Answer

This is easy to do if you use Vim:

  1. Move to the first column of the first line you want to comment.
  2. Press <C-v> (Ctrl+V) to enter block select mode.
  3. Move the selection to the first column of the last line you want to comment.
  4. Type Irem<esc> (Insert, type rem, back to normal mode).

Alternatively, since you seem to be familiar with Python, you could pipe it through this script, then copy the output:

import sys
for line in sys.stdin:
    sys.stdout.write("rem " + line)

CHKDSK /? | python3 comment.py

Comments