0

I'm using the following batch script to process some image files, basically just grabbing some files listed in a txt file and copying it to the current folder.

For %%a in (*.txt) do (
    For /f "delims=" %%N in (%%a) do copy "C:\Files\%%N.jpg" %cd%
)

However it does not work for files with an apostrophe in its name, is there some way to make it work?

  • `For /f "usebackq delims=" %%N in ("%%~a") do copy` – Squashman Feb 18 '21 at 22:51
  • usebackq does not resolve the issue, so it doesn't really matter how many times I was told, thank you. – totalpotato Feb 18 '21 at 23:24
  • Please read [ask] question and provide a [mcve]. Telling us something doesn't work doesn't help anyone help you solve the problem. You need to provide debugging details, error messages and real world examples of your input so that others can reproduce your problem. – Squashman Feb 18 '21 at 23:45
  • If the Codepage in the input file is different then the actual filename of the file, then yes, it would give you that error message. You also have to know what your default code page is for the console. That will also make a difference. – Squashman Feb 19 '21 at 00:52
  • 1
    Regardless, we see the [smart quote problem](https://stackoverflow.com/questions/55144046/capture-2nd-word-from-an-output-in-command-prompt-in-windows) a few times a month here. Which is why providing real world examples of your input is always needed to debug a problem. – Squashman Feb 19 '21 at 01:13

1 Answers1

1

I have found the issue; turns out the files in question were named with a right single quotation mark character (Unicode: U+2019) instead of a normal apostrophe character (Unicode: U+0027), possibly due to some prior mixing with lists in Microsoft Word documents. Microsoft Word has a 'smart quotes' feature that automatically changes normal apostrophes to 'curly quotes', more often seen in publishing than in programming. Programs like notepad++ just use normal apostrophes, so that's what it'll use in a batch file. A simple batch rename of the files will resolve this issue.

  • Yes Unicode code point 2019 is the same is hex 92 in CP1252 (Windows-1252). I deal with that issue all the time. In fact I dealt with it today as I had a client send in millions of records with a mix of x27 and x92. x92 will not covert to EBCDIC x7D when changing the code codepage from 1252 to 37. But if you change 1252 to IS08859-1 and then to 37 it gets converted correctly when transferred to our Enterprise Mainframes. – Squashman Feb 19 '21 at 01:10