Ed Dyreen wrote:But there are still some ANSI characters that just can't be handled in DOS.
Don't sell your code short No pipes, no temp files, it should be immune to codepage/unicode issues.
Liviu
Moderator: DosItHelp
Ed Dyreen wrote:But there are still some ANSI characters that just can't be handled in DOS.
Ed Dyreen wrote: ) do 2>nul md "%%~c" "%%~c\%%~b" "%%~c\%%~b\%%~a" &move /y "%%~§" "%%~c\%%~b\%%~a\%%~§"
foxidrive wrote:©opy[it]®ight wrote:Before i make another attempt to try to sleep, i have a final 'challenge' for you Ed Dyreen.
This is not a place to challenge people to write batch files for you. It makes you seem like a prat who uses other people for your own gain.Make the script so that it doesn't try to create the same folder over and over, but add an IF EXIST statement (like abc0502 did with his script).
Then it will skip the MD command if it encounters an already existing folder
Why?? The overhead of the command and redirecting to nul is small.
And why can't you add an if exist command yourself if you want it?
Code: Select all
) do (if not exist "%%~c\%%~b\%%~a\" md "%%~c\%%~b\%%~a") & move /y "%%~§" "%%~c\%%~b\%%~a\%%~§"
the process cannot access the file because it is being used by another process
Code: Select all
@ECHO OFF
SETLOCAL DisableDelayedExpansion
CLS
TITLE copyitright's stats CoSoLo (Count, Sort, Log) v0.99
SET DATUM=%DATE%
SET TIJD=%TIME%
echo.
ECHO Stats CoSoLo (Count, Sort, Log) v0.99
ECHO -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
echo.
echo.>>stats.log
ECHO [%TIJD% @ %DATUM%] ER ZIJN NOG GEEN BESTANDEN VERPLAATST!
ECHO [%TIJD% @ %DATUM%] ER ZIJN NOG GEEN BESTANDEN VERPLAATST!>>stats.log
goto LOOP
:COUNT
SET DATUM=%DATE%
SET TIJD=%TIME%
IF "%COUNTER%"=="1" (
ECHO [%TIJD% @ %DATUM%] ER IS TOT NU TOE 1 BESTAND VERPLAATST!
ECHO [%TIJD% @ %DATUM%] ER IS TOT NU TOE 1 BESTAND VERPLAATST!>>stats.log
) ELSE (
ECHO [%TIJD% @ %DATUM%] ER ZIJN TOT NU TOE %COUNTER% BESTANDEN VERPLAATST!
ECHO [%TIJD% @ %DATUM%] ER ZIJN TOT NU TOE %COUNTER% BESTANDEN VERPLAATST!>>stats.log
)
:LOOP
:: Code Inspired By abc0502 & Ed Dyreen / Modified by foxidrive & copyitright ::
for %%§ in (
"*.TXT"
) do set "$date=" &for %%? in (
%%~t§
) do if not defined $date set "$date=%%~?" &for /f "tokens=1-3 delims=/-" %%a in (
"%%~?"
) do (if not exist "%%~c\%%~b\%%~a\" md "%%~c\%%~b\%%~a") & (
move /y "%%~§" "%%~c\%%~b\%%~a\%%~§" >NUL
IF ERRORLEVEL 1 goto LOOP
SET /A COUNTER+=1
goto COUNT
)
ping -n 2 127.0.0.1>NUL
goto LOOP
Code: Select all
IF ERRORLEVEL 1 goto LOOP
I think©opy[it]®ight wrote:my console window often gets flooded with the following error:the process cannot access the file because it is being used by another process
the process cannot access the file because it is being used by another process
Code: Select all
@echo off
> locked (
call :exception
)
pause
exit
:exception
:: (
> locked (
echo.fails because file is in use.
)
:: )
exit /b 1
Code: Select all
Het proces heeft geen toegang tot het bestand omdat
het bestand door een ander proces wordt gebruikt.
Druk op een toets om door te gaan. . .
Code: Select all
openFiles /?
Code: Select all
2>nul (
echo.stream 1 'stdout' prints fine
>&2 echo.stream 2 'stderr' won't print because of redirection to nul
)
Code: Select all
@ECHO OFF
SETLOCAL DisableDelayedExpansion
CLS
:LOOP
FOR %%A IN (
"*.txt"
) DO SET "FULL=%%A" &FOR /F "tokens=1 delims= " %%B in (
"%%A"
) DO SET SHORT=%%B &(
ECHO %FULL%
ECHO %SHORT%
echo.
pause
)
EXIT
ip - name - version of script.txt
Code: Select all
set "IP=%%a"
Code: Select all
@echo off & cls
pushd %userprofile%\Desktop\New Folder
Setlocal EnableDelayedExpansion
For /R %%z in (*.txt) Do (
For /F "tokens=1,2,3 delims=-" %%a in ("%%~nz") Do (
set "IP=%%a"
IF not exist "!IP:~0,-1!\" MD "!IP:~0,-1!"
IF exist "%%a-%%b-%%c.txt" ( Move /Y "%%a-%%b-%%c.txt" "!IP:~0,-1!" >nul )
)
)
pause
Code: Select all
@echo off & cls
Setlocal EnableDelayedExpansion
For /R %%z in (*.txt) Do (
For /F "tokens=1,2,3 delims= " %%a in ("%%~nz") Do (
set "IP=%%a"
IF not exist "!IP!" MD "!IP!"
IF exist "%%z" ( Move /Y "%%z" "!IP!" >nul )
)
)
pause
Code: Select all
@echo off
for %%a in (*.TXT) do (
echo %%~ta
for /f "tokens=1-4 delims=/- " %%d in ("%%~ta") do (
for /f %%z in ("%%a") do md "%%g\%%f\%%e\%%z" 2>nul & move /y "%%a" "%%g\%%f\%%e\%%z"
)
)
pause
Code: Select all
@echo off
for %%a in (*.TXT) do (
for /f "tokens=1-4 delims=/- " %%d in ("%%~ta") do (
for /f %%z in ("%%a") do ( if not exist "%%f\%%e\%%d\%%z" md "%%f\%%e\%%d\%%z") & (move /y "%%a" "%%f\%%e\%%d\%%z" >nul
)
)
)
pause
Are you checking to see whether a file exist, or a directory ? And if a file does exist what will happen when you execute makeDir ?©opy[it]®ight wrote:Code: Select all
if not exist "%%f\%%e\%%d\%%z" md "%%f\%%e\%%d\%%z"
Code: Select all
if not exist "%%f\%%e\%%d\%%z\" md "%%f\%%e\%%d\%%z"
Code: Select all
if not exist "%%f\%%e\%%d\%%z" md "%%f\%%e\%%d\%%z"
Code: Select all
1 look ahead and
2 compare result and select action a or b
3a try
3b do not try
Code: Select all
2>nul md "%%f\%%e\%%d\%%z"
Code: Select all
1 set up redirection
2 try
I haven't seen anyone do that in this thread, but when cd starts with a backslash, that is especially important.©opy[it]®ight wrote:if doing cd /? i see that the examples they use start with a backslash.
Are they necessary or can they be left out?
Code: Select all
C:\PROFSYS\ADMIN>cd \
C:\>cd profsys\admin
C:\PROFSYS\ADMIN>cd ..\..\PROFSYS
C:\PROFSYS>cd \admin
C:\ADMIN>