1.

Solve : Limit extension search to 3 characters?

Answer»

Hello I have a reasonably simple problem using the FOR command.

When I execute the batch-file below all *.sas files from the source folder should be copied to the destination folder.

This works basicly but there are also file extensions longer as 3 characters.
For instance LARGE_FILE.sas7bdat
Those files I don't want to be copied.

Somehow the *sas works as if it where *.sas*

I cannot seem to FIX this little error.
It might be a HERITAGE from the old 8.3 filename length times but then there must be some way to exclude the large files with some %%~zF option?
Can anyone help me with that

EDIT: Found the solution by using the following:
for /R %bron% %%F in (*.sas) do ( copy %%~d%%~pF%%~nF.sas o: /Y )
This way only the path and filename are presented in the do-command wich will result in errors if the file LARGE_FILE.sas can not be found because the actual name is LARGE_FILE.sas7bdat but this is no problem to me.

I will LEAVE the post for others to learn from... still think this might be a BUG because the programmers did not anticipate for extensions beyond 3 characters.

============================

Code: [Select]echo off
cls
rem ** copies all *.sas files to folder **
setlocal enabledelayedexpansion
echo The given parameter: %1
echo stop now if the parameter is missing!
SET /P INPUT= continue? (y/n) :
if "%input%" =="y" goto YES
if "%input%" =="Y" goto YES
if "%input%" =="n" goto NO
if "%input%" =="N" goto NO
if "%input%" =="" goto END

:YES
echo.
set bron=X:\SERVER\FOLDER1\FOLDER2\SOURCE\%1\
subst o: /D
c:
cd "\LOCALFOLDER\SUBFOLDER\DESTINATION\"
md %1
cd %1
subst o: .
echo Copying, please wait......
for /R %bron% %%F in (*.sas) do ( copy %%F o: /Y )
del AUTOEXEC.SAS
del BATCH.SAS
echo Copy of %1 has finished.
endlocal
pause
goto END

:NO
echo No actions executed.
goto END

:END
echo End, press any key to continue.
pause >nul
exitWhy not use the following to confirm the input;

Code: [Select]if /I '%input%=='y goto YES
goto no
:yes
/I = ignore case in string

No need to add N check as next line sends all other inputs to :NO

Also...

Code: [Select]cd /d "c:\LOCALFOLDER\SUBFOLDER\DESTINATION\"
Using the /d parameter will also change drive letters as well as path



Discussion

No Comment Found