mario
mario

Reputation: 1543

Command Line For Loop returns path that is missing last subdirectory

I'm trying to use a For Loop to recursively extract all zip files in a folder with multiple levels and even zips within zips. When I run it I get an error message because the last sub directory is blank so it looks like C:\Users\JohnSmith\Desktop\testing\\ and says that it cannot create output directory. I had thought I had had this working earlier but I guess I missed something. Thanks for any and all help!

Here is what I'm running:

FOR /R "C:\Users\JohnSmith\Desktop\testing\" %I IN (*.zip) DO (7z x "%I" -aou -o\"%~dpI\" && del \"%~fI\")

Upvotes: 0

Views: 50

Answers (1)

JosefZ
JosefZ

Reputation: 30113

I guess there all \" are survivals of escaping sequences in your command as if it would call from within some another program. No such need (and even harmful) in pure cmd.

As per 7-zip Command Line Version User's Guide use -o"%~dpI" (remove backslashes); do the same in del "%~fI" as follows

FOR /R "C:\Users\JohnSmith\Desktop\testing\" %I IN (*.zip) DO (7z x "%I" -aou -o"%~dpI" && del "%~fI")

Upvotes: 1

Related Questions