Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

move a fixed number of files between two directories

3,352 views
Skip to first unread message

Tyrser

unread,
Jul 2, 2008, 6:11:51 AM7/2/08
to
Hi all.

I'd like to create a batch file that moves X files from a directory to
another where x is a number;-)
I have a directory with 100000 files and i'd like my script to move 100
files to another dir each time the batch is run.
The goal is to schedule this process so the batch moves e.g. 100 files every
5 minutes untill the source dir is empty.

Any Idea?

Thanks all!


t.m.tr...@gmail.com

unread,
Jul 2, 2008, 6:56:25 AM7/2/08
to

Partially tested (without moving files).

---begin script
@echo off
set SourceDir=C:\dir1
set TargetDir=C:\dir2
set MaxFiles=100
for /f "tokens=1* delims=[]" %%G in ('dir /A-D /B "%SourceDir%\*.*" ^|
find /v /n ""') do (
echo move "%SourceDir%\%%~nxH" "%TargetDir%\"
if %%G==%MaxFiles% exit /b 0)
---end script

Remove 'echo' in 'for' loop to activate the script.

Cheers,

Tomek

Tyrser

unread,
Jul 2, 2008, 7:41:17 AM7/2/08
to
<t.m.tr...@gmail.com> ha scritto nel messaggio
news:4899dbed-f9ce-4b6e...@y21g2000hsf.googlegroups.com...

> Cheers,
>
> Tomek

Wow thank you!
I'm just tuning it and it's perfect

Tyrser


001.d...@gmail.com

unread,
Jul 4, 2008, 5:32:10 AM7/4/08
to

@echo off
for %%i in (SourceDir\*) do call:move %%i
goto:eof

:move
set /a ind+=1
if %ind% gtr 100 exit /b
move "%1" DestDir\

hvd...@gmail.com

unread,
Mar 25, 2017, 11:02:18 PM3/25/17
to
Vào 17:56:25 UTC+7 Thứ Tư, ngày 02 tháng 7 năm 2008, t.m.tr...@gmail.com đã viết:
wow! thank you very much :)
Can you help me answer this question?
I have a folder contains many files, and I want to rename that files to MD5 and remove extension. Eg: newfile.exe -> 3AC712D4AA6102D2439C810D958FD5A9. What script do that? Thank you!

Herbert Kleebauer

unread,
Mar 26, 2017, 4:47:51 AM3/26/17
to
On 26.03.2017 05:02, hvd...@gmail.com wrote:


> I have a folder contains many files, and I want to rename that
> files to MD5 and remove extension.
> Eg: newfile.exe -> 3AC712D4AA6102D2439C810D958FD5A9.

@echo off
for /f %%i in ('dir /b /a-d *.*') do (
for /f "tokens=1-16" %%j in ('CertUtil -hashfile %%i MD5') do (
call set a=%%b%%
set b=%%j%%k%%l%%m%%n%%o%%p%%q%%r%%s%%t%%u%%v%%w%%x%%y)
call echo ren %%i %%a%%)



hvd...@gmail.com

unread,
May 5, 2017, 11:09:32 AM5/5/17
to
Vào 15:47:51 UTC+7 Chủ Nhật, ngày 26 tháng 3 năm 2017, Herbert Kleebauer đã viết:
thank you very much :) It runs well!
Can you help me one more time?
Eg: I have a folder A contains 100.000 files. I want to have a code that click one time move 5000 files from A to folder 1, 2, ..., 19, 20.
I try above code but with folder A I have to edit folder names and click .bat file 20 times. I have many same folders. It takes a long time!
@echo off
set SourceDir=C:\dir1
set TargetDir=C:\dir2
set MaxFiles=100
for /f "tokens=1* delims=[]" %%G in ('dir /A-D /B "%SourceDir%\*.*" ^|
find /v /n ""') do (
move "%SourceDir%\%%~nxH" "%TargetDir%\"
if %%G==%MaxFiles% exit /b 0)

Help me please. Thank you!

Herbert Kleebauer

unread,
May 5, 2017, 6:31:01 PM5/5/17
to
On 05.05.2017 17:09, hvd...@gmail.com wrote:

> Eg: I have a folder A contains 100.000 files. I want to have a
> code that click one time move 5000 files from A to folder 1, 2, ..., 19, 20.

@echo off
set SourceDir=C:\dir1
set TargetDir=C:\dir2
set MaxFiles=100

set m=0
set n=0

for /f %%i in ('dir /b /a-d "%SourceDir%\*.*"') do call :sub %%i
goto :eof

:sub
if not %m%==0 goto :s1
set /a n=n+1
mkdir %TargetDir%\%n%
set m=%MaxFiles%

:s1
move %SourceDir%\%1 %TargetDir%\%n%\ >nul
set /a m=m-1
goto :eof

hvd...@gmail.com

unread,
May 6, 2017, 12:49:22 PM5/6/17
to
Vào 05:31:01 UTC+7 Thứ Bảy, ngày 06 tháng 5 năm 2017, Herbert Kleebauer đã viết:
sorry, I don't know anything about codes. Can you show me what and where I have to edit?
Eg: Folder D:\A contains 100 files, maxfiles=20, and subfolder D:\A\1, ..., D:\A\5
Thank you very much!

Herbert Kleebauer

unread,
May 7, 2017, 3:37:12 AM5/7/17
to
On 06.05.2017 18:49, hvd...@gmail.com wrote:

>> > Eg: I have a folder A contains 100.000 files. I want to have a
>> > code that click one time move 5000 files from A to folder 1, 2, ..., 19, 20.
>>
>> @echo off
>> set SourceDir=C:\dir1
>> set TargetDir=C:\dir2
>> set MaxFiles=100
>>
>> set m=0
>> set n=0
>>
>> for /f %%i in ('dir /b /a-d "%SourceDir%\*.*"') do call :sub %%i
>> goto :eof
>>
>> :sub
>> if not %m%==0 goto :s1
>> set /a n=n+1
>> mkdir %TargetDir%\%n%
>> set m=%MaxFiles%
>>
>> :s1
>> move %SourceDir%\%1 %TargetDir%\%n%\ >nul
>> set /a m=m-1
>> goto :eof
>
> sorry, I don't know anything about codes.

Sorry, but if you want to use batch files, you have
to learn at least the basics. Batch files are not
ready-to-use programs.

> Can you show me what and where I have to edit?

These are your lines of code, I didn't modify them:

>> set SourceDir=C:\dir1
>> set TargetDir=C:\dir2
>> set MaxFiles=100


> Eg: Folder D:\A contains 100 files, maxfiles=20, and subfolder D:\A\1, ..., D:\A\5

And why don't you change your own lines to:

set SourceDir=D:\A
set TargetDir=D:\A
set MaxFiles=20



hvd...@gmail.com

unread,
May 7, 2017, 10:51:30 AM5/7/17
to
Vào 14:37:12 UTC+7 Chủ Nhật, ngày 07 tháng 5 năm 2017, Herbert Kleebauer đã viết:
OMG! Sorry! Yesterday I copied missing some codes. It makes me can't understand your codes. Today It run perfectly! Thank you very much! Have a nice day :)

al.r.sp...@gmail.com

unread,
Mar 16, 2018, 11:32:25 AM3/16/18
to
Herb! Thanks so much. this saved me a huge amount of work and time

Andy Ho

unread,
Mar 10, 2023, 11:55:03 AM3/10/23
to
cannot works, please help

Herbert Kleebauer

unread,
Mar 11, 2023, 3:30:29 AM3/11/23
to
On 10.03.2023 17:55, Andy Ho wrote:
> On Sunday, May 7, 2017 at 2:37:12 PM UTC+7, Herbert Kleebauer wrote:
>> On 06.05.2017 18:49, hvd...@gmail.com wrote:
>>
>> >> > Eg: I have a folder A contains 100.000 files. I want to have a
>> >> > code that click one time move 5000 files from A to folder 1, 2, ..., 19, 20.
>> >>
>> >> @echo off
>> >> set SourceDir=C:\dir1
>> >> set TargetDir=C:\dir2
>> >> set MaxFiles=100
>> >>
>> >> set m=0
>> >> set n=0
>> >>
>> >> for /f %%i in ('dir /b /a-d "%SourceDir%\*.*"') do call :sub %%i
>> >> goto :eof
>> >>
>> >> :sub
>> >> if not %m%==0 goto :s1
>> >> set /a n=n+1
>> >> mkdir %TargetDir%\%n%
>> >> set m=%MaxFiles%
>> >>
>> >> :s1
>> >> move %SourceDir%\%1 %TargetDir%\%n%\ >nul
>> >> set /a m=m-1
>> >> goto :eof

> cannot works, please help

If you want help, you have to be little bit more specific.
What exactly do you want to do and and what doesn't work?



Zaidy036

unread,
Mar 11, 2023, 8:57:30 PM3/11/23
to
On 3/10/2023 11:55 AM, Andy Ho wrote:
> On Sunday, May 7, 2017 at 2:37:12 PM UTC+7, Herbert Kleebauer wrote:
>> On 06.05.2017 18:49, hvd...@gmail.com wrote:
>>
>>>>> Eg: I have a folder A contains 100.000 files. I want to have a
>>>>> code that click one time move 5000 files from A to folder 1, 2, ..., 19, 20.
>>>>
>>>> @echo off
>>>> set SourceDir=C:\dir1
>>>> set TargetDir=C:\dir2
>>>> set MaxFiles=100
>>>>
>>>> set m=0
>>>> set n=0
>>>>
>>>> for /f %%i in ('dir /b /a-d "%SourceDir%\*.*"') do call :sub %%i
>>>> goto :eof
>>>>
>>>> :sub
>>>> if not %m%==0 goto :s1
>>>> set /a n=n+1
>>>> mkdir %TargetDir%\%n%
>>>> set m=%MaxFiles%
>>>>
>>>> :s1
I would make a versitile batch using START <path>\MoveFiles.bat %1 %2

If always the same folders make a shortcut to the batch

%1 is source and %2 is destination so for you:
START <path>\MoveFiles.bat "C:\dir1" "C:\dir2"
- Note that %1 and %2 do not require " " if no spaces in them.
- X: below represents any Full Path

:: File names from %1 into FilesToMove.txt
DIR /A:D /B %1 > X:\FilesToMove.txt

:: Count files in FilesToMove.txt
FOR /f %%A in ('X:\FilesToMove.txt ^| FIND /V /C ""') DO SET cnt=%%A

:: Limit or remove for all
IF %cnt% GTR 5000 SET cnt=5000

:: Use this for test runs and delete later if no problems
SET cnt=5

FOR /L %%t IN (1,1,%cnt%) DO (
SET /p OneFile=< X:\FilesToMove.txt
COPY %1\!OneFile! %2\
MORE +1 X:\FilesToMove.txt
)

EXIT

Loop explanation (no comments allowed in a loop)
- SET changes variable to first file name
- COPY does the work for test runs so change to MOVE if no problems
- MORE +1 removes the first file from X:\FilesToMove.txt

mokomoji

unread,
Mar 25, 2023, 12:16:11 PM3/25/23
to
2008년 7월 2일 수요일 오후 7시 11분 51초 UTC+9에 Tyrser님이 작성한 내용:
sample make file 300
--------------------------------------------------------------------------------
@echo off
setlocal
cd /d "%~dp0"
set "z_target=.\abc"
if exist "%z_target%" rd /q /s "%z_target%"
if not exist "%z_target%" md "%z_target%"

for /l %%l in (1,1,300) do (
call set z_num=%%random%%
call echo.%%l_%%z_num%%
cmd /c "echo.%%l_%%z_num%%>%z_target%\%%l_%%z_num%%.txt"
)
endlocal
pause

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

ping -n2 time to file 10ea
--------------------------------------------------------------------------------------------
@echo off
setlocal
cd /d "%~dp0"
set "z_source=.\abc"
set "z_target=.\def"
set "z_t_file=*.txt"
set "z_sum=0"
set "z_f_num=10"
set "z_time=ping localhost -n 2 >nul"


if not exist "%z_target%" md "%z_target%"

for /f %%f in ('dir /b "%z_source%\%z_t_file%"') do (
call set /a "z_sum=%%z_sum%%+1"
call set /a "z_sum2=!(%%z_sum%% %%%% %z_f_num%)"
call echo %%z_sum2%%|find "1" 2>nul>nul&&(
%z_time%
)

echo move "%z_source%\%%~f" "%z_target%"
move "%z_source%\%%~f" "%z_target%"
)
endlocal
pause

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

timeout command use delay

----------------------------------------------------------------------------------------
@echo off
setlocal
cd /d "%~dp0"
set "z_source=.\abc"
set "z_target=.\def"
set "z_t_file=*.txt"
set "z_sum=0"
set "z_f_num=10"
set "z_time=timeout /t 10 >nul"


if not exist "%z_target%" md "%z_target%"

for /f %%f in ('dir /b "%z_source%\%z_t_file%"') do (
call set /a "z_sum=%%z_sum%%+1"
call set /a "z_sum2=!(%%z_sum%% %%%% %z_f_num%)"
call echo %%z_sum2%%|find "1" 2>nul>nul&&(
%z_time%
)

echo move "%z_source%\%%~f" "%z_target%"
move "%z_source%\%%~f" "%z_target%"
)
endlocal
pause





mokomoji

unread,
Mar 25, 2023, 2:52:15 PM3/25/23
to
2008년 7월 2일 수요일 오후 7시 11분 51초 UTC+9에 Tyrser님이 작성한 내용:
sample2.cmd
--------------------------------------------------------------------------------------------------------
@echo off
setlocal
cd /d "%~dp0"
set "z_target=.\abc"
set "z_source=.\def"
if exist "%z_target%" rd /q /s "%z_target%"
if exist "%z_source%" rd /q /s "%z_source%"
if not exist "%z_target%" md "%z_target%"

for /l %%l in (1,1,300) do (
call set z_num=%%random%%
call echo.%%l_[%%z_num%%]
cmd /c "echo.%%l_%%z_num%%>%z_target%\%%l_[%%z_num%%].txt"
)
endlocal
pause
-------------------------------------------------------------------------------------------------------------
type sample make
filenamenumber_[number].txt
--------------------------------------------------------------------------------------------------------------

10 EA cut file time schedule [SCHTASKS] command type source
-------------------------------------------------------------------------------------------------------------
@echo off
setlocal
cd /d "%~dp0"
set "z_source=.\abc"
set "z_target=.\def"
set "z_t_file=*.txt"
set "z_f_num=10"
if not exist "%z_target%" md "%z_target%"

for /f %%f in ('dir /b "%z_source%\%z_t_file%"') do (
call echo. "%%~f"
cmd /c "if %%z_f_num%% gtr 0 move "%z_source%\%%~f" "%z_target%""&&set /a "z_f_num-=1
call echo [%%z_f_num%%]|find "[1]" 2>nul>nul&&goto :end
)

:end
endlocal
pause
------------------------------------------------------------------------------------------------------------------

mokomoji

unread,
Mar 25, 2023, 3:23:18 PM3/25/23
to
2023년 3월 26일 일요일 오전 3시 52분 15초 UTC+9에 mokomoji님이 작성한 내용:
bug fix - sample type recursion source
------------------------------------------------------------------
@echo off
setlocal
cd /d "%~dp0"
set "z_source=.\abc"
set "z_target=.\def"
set "z_t_file=*.txt"
set "z_f_num=100"
if not exist "%z_target%" md "%z_target%"

for /r "%z_source%" %%f in (*.*) do (
echo. "%%~nxf"
cmd /c "if %%z_f_num%% gtr 0 move "%%~f" "%z_target%""&&set /a "z_f_num-=1
call echo [%%z_f_num%%]|find "[0]" 2>nul>nul&&goto :end
)

:end
endlocal
pause
--------------------------------------------------------------------
all source fix {find "[1]" change to find "[0]"}


Andy Ho

unread,
Jun 14, 2023, 1:53:52 PM6/14/23
to
only 3 folder was created and the file not all moved (only 5 files and the rest still in the first folder)

Herbert Kleebauer

unread,
Jun 15, 2023, 7:45:25 AM6/15/23
to
An answer 3 month later?! If you are still interested, we can
take a closer look why it doesn't work for you. But that doesn't
work if you post only every few month.

But first check, if there are file names with spaces
or other poisoned charters like !%&|^



R.Wieser

unread,
Jun 15, 2023, 7:56:50 AM6/15/23
to
@OP:

> But first check, if there are file names with spaces
> or other poisoned charters like !%&|^

Better yet : display all filenames and compare them with the result you got.
Perhaps its your script which only "sees" the files you saw copied.

IOW, make sure that your script iterates thru all the expected files.

Regards,
Rudy Wieser


Jüri Tasuja

unread,
Jul 4, 2023, 9:57:40 AM7/4/23
to
Hi,
I tried to modify this script by deleting all n parts so it won't produce all these folders but still moves files in sets. But it seems like it's not so straight forward as I thought.
What I try to do is to move (sort) sets of images (3 images in each set) to 2 different folder.
Condition for moving is difference in file sizes %%z1 within these 3 image sets. If image sizes differs less than e.g. 2 kB among any of these 3 images then the set goes to one folder if else then to other folder. Is anyone who could help on this? Many thanks!


Herbert Kleebauer

unread,
Jul 5, 2023, 7:05:33 AM7/5/23
to
On 04.07.2023 15:57, Jüri Tasuja wrote:


> What I try to do is to move (sort) sets of images (3 images in each set)
> to 2 different folder.

Without giving any information how the 3 files of a set can be found,
nobody can help. Do they have the same name but a different extension?
Or is there a common prefix in the file name? Or is there only one
set in the source directory?

Jüri Tasuja

unread,
Jul 5, 2023, 7:43:05 AM7/5/23
to
Images are .jpg images from trail camera where camera was set to shoot 3 pictures in the row when activated. Camera saves all pictures in one folder. Pictures have all different names e.g.
"E:\IMG_0001.JPG"
"E:\IMG_0002.JPG"
"E:\IMG_0003.JPG"
"E:\IMG_0004.JPG"
"E:\IMG_0005.JPG"
"E:\IMG_0006.JPG"
"E:\IMG_0007.JPG"
"E:\IMG_0008.JPG"
"E:\IMG_0009.JPG"
My thought was to somehow to store 3 images temporarily then compare their sizes and then pass to right folder. At the moment images are sent straight to the destination folder in the cycle.
To explain why I need such sorting is that many times trail camera is activated by wind movement and it creates lots of "empty" images without animals. These empty 3 image sets are usually very similar in size maybe differing 1 or 2 kB and thus hopefully possible to sort out by image size condition.

Jüri Tasuja

unread,
Jul 5, 2023, 7:50:50 AM7/5/23
to
On Wednesday, 5 July 2023 at 14:05:33 UTC+3, Herbert Kleebauer wrote:
So far I modified one of the script that moves images from one folder to other. Counter of the script works well with images but it sends them away one by one before it is possible to compare these.

@echo off
set SourceDir=E:\
set TargetDir=E:\new\
set MaxFiles=3
set m=0

for /f %%i in ('dir /b /a-d "%SourceDir%\*.*"') do call :sub %%i
goto :eof

:sub
if not %m%==0 goto :s1
set m=%MaxFiles%

:s1
move %SourceDir%\%1 %TargetDir%\ >nul

Herbert Kleebauer

unread,
Jul 5, 2023, 4:22:20 PM7/5/23
to
On 05.07.2023 13:43, Jüri Tasuja wrote:

> Images are .jpg images from trail camera where camera was set to shoot 3 pictures in the row when activated. Camera saves all pictures in one folder. Pictures have all different names e.g.
> "E:\IMG_0001.JPG"
> "E:\IMG_0002.JPG"
> "E:\IMG_0003.JPG"
> "E:\IMG_0004.JPG"
> "E:\IMG_0005.JPG"
> "E:\IMG_0006.JPG"
> "E:\IMG_0007.JPG"
> "E:\IMG_0008.JPG"
> "E:\IMG_0009.JPG"
> My thought was to somehow to store 3 images temporarily then compare their sizes and then pass to right folder. At the moment images are sent straight to the destination folder in the cycle.
> To explain why I need such sorting is that many times trail camera is activated by wind movement and it creates lots of "empty" images without animals. These empty 3 image sets are usually very similar in size maybe differing 1 or 2 kB and thus hopefully possible to sort out by image size condition.


@echo off
set SourceDir=E:\
set TargetDir1=E:\new1\
set TargetDir2=E:\new2\

set n=0
for /f %%i in ('dir /b /on "%SourceDir%*.jpg"') do call :sub %%i
goto :eof

:sub
set file1=%file2%
set size1=%size2%
set file2=%file3%
set size2=%size3%
set file3=%1
set size3=%~z1

set /a n=n+1
if not %n%==3 goto :eof
set n=0

echo compare file size of %file1% (%size1%) %file2% (%size2%) %file3% (%size3%)
set max=%size1%
if %size2% gtr %max% set max=%size2%
if %size3% gtr %max% set max=%size3%

set min=%size1%
if %size2% lss %min% set min=%size2%
if %size3% lss %min% set min=%size3%

set /a diff=max-min

if %diff% gtr 2000 (
move %file1% %TargetDir1%>nul
move %file2% %TargetDir1%>nul
move %file3% %TargetDir1%>nul
) else (
move %file1% %TargetDir2%>nul
move %file2% %TargetDir2%>nul
move %file3% %TargetDir2%>nul)







Jüri Tasuja

unread,
Jul 6, 2023, 6:59:20 AM7/6/23
to
Many thanks for script! Unfortunately I can't get it working. I have tested it and the script itself is working just perfectly but it fails when moving files where it gives message "Access denied". I googled the problem and one explanation is that when source file is in use then "move" don't work so I changed "move" function with "robocopy" and now it don't give any message but not moving the files.

robocopy %file1% %TargetDir1%>nul /A /MOV

I also tried to run as administrator but then script failed to find file size "set size3="
Also it seems that %~z1 works only with local folders and failed with my external hard drive to give file size.
Could you possibly have idea why it's not moving files.

Herbert Kleebauer

unread,
Jul 6, 2023, 12:59:41 PM7/6/23
to
On 06.07.2023 12:59, Jüri Tasuja wrote:

>> set SourceDir=E:\
>> set TargetDir1=E:\new1\
>> set TargetDir2=E:\new2\
>>
>> set n=0
>> for /f %%i in ('dir /b /on "%SourceDir%*.jpg"') do call :sub %%i
>> goto :eof

> Many thanks for script! Unfortunately I can't get it working.
> I have tested it and the script itself is working just perfectly
> but it fails when moving files where it gives message "Access denied".

"Move" can only be used when source and destination are on the
same drive. To avoid problems with different drive letters
assigned to the external drive, I would do it manually:

After connecting the external drive, use Windows Explorer to
copy all the jpgs to a local folder, for example to d:\my_jpgs
and use:

set SourceDir=d:\my_jpgs\
set TargetDir1=d:\my_jpgs\new1\
set TargetDir2=d:\my_jpgs\new2\

in your batch file (don't forget to create the two target
directories or create them in the batch if they don't exists).

If all is ok, use Explorer to delete the jpgs on the external
drive and to unmount the drive.





Kenny McCormack

unread,
Jul 6, 2023, 3:21:32 PM7/6/23
to
In article <u86rtq$105ki$1...@dont-email.me>,
Herbert Kleebauer <kl...@unibwm.de> wrote:
...
>"Move" can only be used when source and destination are on the
>same drive.

I may have misunderstood the bigger picture here - I have not closely
followed this thread, although I have read all the posts - but "move" (in
DOS/Windows/CMD.EXE) definitely can and does move files between drives.

I assume it is implemented as a copy followed by a delete. (For
completeness): If the files are on the same drive, then a simple rename is
performed.

Of course, "rename" only works on a single drive...
--
Hindsight is (supposed to be) 2020.

Trumpers, don't make the same mistake twice.
Don't shoot yourself in the feet - and everywhere else - again!.

Jüri Tasuja

unread,
Jul 6, 2023, 3:47:36 PM7/6/23
to
Thanks again I got it working! I understood my mistake, I had one extra subfolder between pictures and C: drive. These "move" and %~z are quite picky functions. Meanwhile I found one script from Stackoverflow by XFlak who claims that it gets file size from every directory (external etc.). Script added below:
set file=C:\Users\Admin\Documents\test.jpg
set /a filesize=
set fileExclPath=%file:*\=%

:onemoretime
set fileExclPath2=%fileExclPath:*\=%
set fileExclPath=%fileExclPath2:*\=%
if /i "%fileExclPath%" NEQ "%fileExclPath2%" goto:onemoretime

dir /s /a-d "%workingdir%">"%temp%\temp.txt"
findstr /C:"%fileExclPath%" "%temp%\temp.txt" >"%temp%\temp2.txt"

set /p filesize= <"%temp%\temp2.txt"

echo set filesize=%%filesize: %fileExclPath%%ext%=%% >"%temp%\temp.bat"
call "%temp%\temp.bat"

:RemoveTrailingSpace
if /i "%filesize:~-1%" EQU " " set filesize=%filesize:~0,-1%
if /i "%filesize:~-1%" EQU " " goto:RemoveTrailingSpace

:onemoretime2
set filesize2=%filesize:* =%
set filesize=%filesize2:* =%
if /i "%filesize%" NEQ "%filesize2%" goto:onemoretime2

set filesize=%filesize:,=%
echo %filesize% bytes

SET /a filesizeMB=%filesize%/1024/1024
echo %filesizeMB% MB

SET /a filesizeGB=%filesize%/1024/1024/1024
echo %filesizeGB% GB

Herbert Kleebauer

unread,
Jul 6, 2023, 4:02:49 PM7/6/23
to
On 06.07.2023 21:21, Kenny McCormack wrote:

>>"Move" can only be used when source and destination are on the
>>same drive.
>
> I may have misunderstood the bigger picture here - I have not closely
> followed this thread, although I have read all the posts - but "move" (in
> DOS/Windows/CMD.EXE) definitely can and does move files between drives.

You are right. I shouldn't rely on my memories, but always check it.

Jüri Tasuja

unread,
Jul 6, 2023, 4:10:00 PM7/6/23
to
Herbert I tested your script on external hard drive as well and it works like charm there as well. Only condition is that folder with pictures must be on directory like you had in example.
It's not all. Still I wanted to test script this way on external hard drive as well does it fail or not but I forgot to change the script directories C: to E: and script still worked. It moved pictures from E: drive to C: drive:
set SourceDir=E:\my_jpgs\ ->images were taken from here and bat script was run here
set TargetDir1=E:\my_jpgs\new1\
set TargetDir2=E:\my_jpgs\new2\

but in script I forgot to change directories and files were sent to targetdirectories shown below.
set SourceDir=c:\my_jpgs\
set TargetDir1=c:\my_jpgs\new1\
set TargetDir2=c:\my_jpgs\new2\
So script works between directories too.

Jüri Tasuja

unread,
Jul 6, 2023, 4:12:36 PM7/6/23
to
Thanks again, this piece of script helps me lot!

Robert Roland

unread,
Jul 6, 2023, 5:18:45 PM7/6/23
to
On Thu, 6 Jul 2023 19:21:30 -0000 (UTC), gaz...@shell.xmission.com
(Kenny McCormack) wrote:

>If the files are on the same drive, then a simple rename is
>performed.

That is correct. In some cases, it is important to remember that the
file's permissions will be retained when it is moved within the same
volume.

If you want the file to inherit the permissions from the destination
directory, you can perform a copy and delete in stead of a move.
--
RoRo

Kenny McCormack

unread,
Jul 6, 2023, 5:41:40 PM7/6/23
to
In article <spbeaitk9c4vpi370...@4ax.com>,
Assuming we are talking about the same thing...

Yes, I get bit by this from time to time when I have a file in a non-shared
area on a drive, and I move it into a shared area (E.g., from
Z:\what\ever\foo.txt" to "Z:\shared"). I find that if I try to access the
file through the shared drive (e.g., with Samba from a Linux machine), I
get Access Denied messages. Now, as it happens, I have a script (written
in a certain Windows scripting language - not batch - that gives access to
system [API] functions) that will force the permissions of a file to be
re-calculated - fixing the issue. This saves you the bother of a copy/delete.

--
If you think you have any objections to anything I've said above, please
navigate to this URL:
http://www.xmission.com/~gazelle/Truth
This should clear up any misconceptions you may have.

Andy Ho

unread,
Jul 25, 2023, 1:42:43 PM7/25/23
to
sorry sir for late reply.

yes, poisoned character is #, my filename is: aaa#bbb#ccc.mpg

thanks
0 new messages