0

Referring to this post, recursively add file extension to all files, I am trying to recursively add extensions to many files within many separate subfolders. All of the files appearing at the end of my subfolders do not have any extension at all, and I would like to give them all a .html extension.

I have tried the following in my command prompt after using cd to change to the parent directory that I would like to use:

find /path -type f -not -name "*.*" -exec mv "{}" "{}".html \;

However, I receive the following error: "FIND: Invalid switch"

I am new to using the command prompt for this type of manipulation, so please excuse my ignorance. I am thinking that maybe I have to change the /path to the directory I want it to look through, but I tried that to no avail.

I have also tried the following command:

find . -type f -exec mv '{}' '{}'.html \;

and receive the following error: FIND: Parameter format not correct

I am running Windows 10.

Community
  • 1
  • 1
Chris K
  • 21
  • 4

3 Answers3

0

-not is an archaic form of logical negation; the current form is ! (exclamation). It has to be followed by a boolean expression. In this case, you followed it with -name, which fouled the command line parsing. -name is another option, not a valid expression operator.

You need to build the negation within your regular expression: negate the period, not the entire name.


I see another strong indicator: what is FIND? The command you supposedly ran is find; UNIX is case-significant. At whatever command line you're using, type man find or find --help to get a list of options and semantics. I'm worried that the bash you have under Windows isn't full-featured.


Are you familiar with the Windows command rename? It has a syntax similar to the UNIX mv, although it will work on multiple files. For instance

rename [^.]* *.html

I think would work for a single directory.

Prune
  • 76,765
  • 14
  • 60
  • 81
  • Thanks for catching that, too. I was trying to run this UNIX code and Bash commands directly into the windows cmd prompt. – Chris K Oct 14 '16 at 22:19
0

Seems like -not isn't available in your find version, use ! instead:

find /path -type f \! -name "*.*" -exec mv "{}" "{}".html \;

From find manual:

-not expr

 Same as ! expr, but not POSIX compliant.
Jahid
  • 21,542
  • 10
  • 90
  • 108
0

Apologies to all who commented and left answers. I believe I was unclear that I was trying to use this specifically from the windows cmd prompt. I used the following to add extensions to all files at the end of my subfolders:

FOR /R %f IN (*.) DO REN "%f" *.html 
Chris K
  • 21
  • 4