1.

Solve : files archive with drag and drop?

Answer»

Hello,

I have files with the samen filename but different file extensions.
With drag and drop of only 1 file, no-matters what the file extension is, i want to archive
all these files to one archive with the common filename.

I try this but it's not working for filenames with a sepparator in the filename.

-------------------------------------------------------------
cls

echo on

SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:
 
for /f "tokens=* delims= " %%F in ('echo %fName%') do (


rem echo REN %%~NXF %%~nF

rar a -ag[dd-mm-yyyy] %%~nF.rar %%~nF.*

)


------------------------------

cls

echo on

SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if '%1' equ '' set /p fName=Enter file name:
 
for /f "tokens=* delims= " %%F in ('echo %fName%') do (


rem echo REN %%~nxF %%~nF

rar a -ag[dd-mm-yyyy] %%~nF.rar %%~nF.*

)



thanks jrom



You need to surround the pathways in quotes or it will interpret them as multiple arguments.

I also made your for loop a little simpler.  Not SURE if you want to keep those changes.

Code: [Select]cls

echo on

SETLOCAL ENABLEDELAYEDEXPANSION

set fName=%1
if "%1"=="" set /p fName=Enter file name:
 
for /f "delims=" %%F in ("%fName%") do (

echo REN "%%~nxF" "%%~nF"

rar a -ag[dd-mm-yyyy] "%%~nF.rar" "%%~nF.*"

)

You don't need a loop:

Code: [Select]echo off
rar a -ag[dd-mm-yyyy] "%~n1.rar" "%~dpn1.*" Quote from: foxidrive on May 10, 2014, 09:12:14 AM

You don't need a loop:

Code: [Select]echo off
rar a -ag[dd-mm-yyyy] "%~n1.rar" "%~dpn1.*"

The loop allows for no input to be specified until the program runs, otherwise you will run it with %1 equal to nul. Quote from: Lemonilla on May 10, 2014, 11:21:53 PM
The loop allows for no input to be specified until the program runs, otherwise you will run it with %1 equal to nul.

Yes Lemonilla, the code doesn't allow for input but the thread is all about drag and drop on a batch file. 

Hi ,

Thanks all for your help.

Both scripts are use-able for me.
Only files with spaces in the filename are not archived.
How can this be DONE?

thanks in advance

jromWhich solution did you try?

Both Lemonilla's and mine preserve spaces - Lemonilla's code needs a %~1 so that the IF compare doesn't FAIL but the rar terms are quoted.

Are you using a modern version of RAR?Both scriptsRAR 5.10 beta 4Try this code and copy/paste the result on the SCREEN here in a reply.  Use a filename with spaces.

Code: [Select]echo off
echo %1
echo rar a -ag[dd-mm-yyyy] "%~n1.rar" "%~dpn1.*"
pauseHi foxidrive.

This is working correct, now i can also archive files with a space in the filename.
Thanks a lot.

jromSo what did you change? The only difference in Foxidrive's code was he put an echo statement so we could see the command it would execute without it executing.


Discussion

No Comment Found