Reputation: 47
I'm trying to scan files in directorys for text inside, but whenever I come across a file that has the ' - Copy' added to the end of it from windows, the program will not read it. I've tried using quotes within the name being passed, but no dice.
FOR /R %%F in (*.CDP) do (
for /f "tokens=*" %%a in (%%~nxF) do (
I've been using this code and have no issues with the typical files Im seeing. however if its something like dummy_file - Copy, I will get an error from the program saying 'System cannot find the file dummy_file.' period included. If I use
FOR /R %%F in (*.CDP) do (
for /f "tokens=*" %%a in ("%%~nxF") do (
Then the second for loop gets skipped, and the program proceeds on. I thought this would made the loop take it as a string literal, but apparently the for loop has its own way of reading things.
Is it possible to accept files in this loop that have a - Copy in them? Will I be able to use dummy_file - Copy.cdp here?
Upvotes: 1
Views: 101
Reputation: 70923
for /R %%F in (*.CDP) do (
for /F "usebackq delims=" %%A in ("%%~fF") do (
Changes:
Instead of retrieving all tokens, this code disables the delimiters
As the file name is quoted, usebackq
is include to indicate that we are not processing a direct string, but the file contents
As the code recurses folders, if the idea is to read the file contents then instead of directly using the file name and extension, the full path is needed as the file location can differ from current directory
Upvotes: 1