0

Long time lurker, first time poster.

I've looked around this site, I've googled, I've experimented. And, while I'm very, very close to where I want to go, there's one last hurdle I can't seem to get over. I would have posted a response to this thread...

How do I create separate zip files for each selected file/directory in 7zip?

..but I guess the passage of time has disallowed further comments to that post.

Anyway, here's what I want to accomplish in 7zip, from the command line: -compress each individual file to its own archive -maintain directory structure -have the archives be in the same folders where their per-archived counterparts originated -delete the original file after archiving

This command has got me so close...

FOR /R %i IN (*.*) DO "C:\Program Files\7-Zip\7z.exe" a "%i.7z" "%i" -sdel

That command archives each individual file. It maintains the files in the directory structure. It deletes the original file after archiving. But, the naming is just a bit off. Example: I archive a file named "handsome.txt". Rather than leave me with the desired archive name of "handsome.7z", it leaving me with an archive called "handsome.txt.7z".

How in the world do I run this command, while having the archive names stop containing the original extension?

Thanks in advance.

1 Answers1

1

In your command, when FOR /R scans the folder structure the parameter "%i" expands to each filename and extension but"%~dpni" will get just the path+filename without the extension. So try this to make the 7z file name as you want (you are just changing "%i.7z" to "%~dpni.7z"):

FOR /R %i IN (*.*) DO "C:\Program Files\7-Zip\7z.exe" a "%~dpni.7z" "%i" -sdel

To see an explanation of how the tilde ~ character can modify variable substitution, including FOR metavariable expansion, type FOR /? at the prompt or see online references like these

Parameter extensions

Or look for 'variable substitution' here:

Windows Commands: FOR