ForFiles works in C: and Downloads but not in Documents folder in One Drive

98 Views Asked by At

I have a Batch file that looks for old versions of duplicated Access DB files on a shared account. I can get it to find and delete files on the c:, and network drives, and in my downloads folder, but not on my Documents folder. I want to backup and clean up files in my One Drive so users can access them remotely if needed.

The C: drive version works great. But is on the local machine. ForFiles /P C:\COOP\ContactsDb_Backup\Daily\ /S /M *.mdb /D -5 /C "cmd /c del @file /q"

I can get a version matching files in my downloads folder. ForFiles /P "%userprofile%\Downloads" /M *.mdb /C "cmd /c echo @path /q"

But I can't get even a file match in my ForFiles /P "%userprofile%\Documents" /M *.mdb /C "cmd /c echo @path /q"

I am constantly getting

"ERROR: Invlaid argument/option - '@path'.

I tried using the %username% in the path C:\Users\%username%\Documents\ as well but I think I don't really understand.

I can get it to work on the C: drive:

(ForFiles /P C:\COOP\ContactsDb_Backup\Daily\ /S /M *.png /D -5 /C "cmd /c @file")

But not on files in \Documents for One Drive:

I have tried wrtiting the path to the One Drive files using:

%userprofile% (ForFiles /P "%userprofile%\Documents\" /M *.png /C "cmd /c echo @path")
%username% (ForFiles /P "C:\Users\%username%\Documents\" /M *.png /C "cmd /c echo @path")

I have tried with and without double quotes. All the examples I can find are using \Downloads and that works fine for me as well.

0

There are 0 best solutions below