Batch file 创建批处理文件以将图片复制到网络驱动器
如何创建一个批处理文件,将文件从相机复制到命令行提示的目录 文件夹结构示例:{共享驱动器启动文件夹}[复制后删除图片] 我想让这项工作,以复制照片从不同的相机到一个共享文件夹,并有它所有的排序按年份,然后月份,最后按用户提示的名称。我只知道很少的命令行命令,所有的开关和%。。我很快就迷路了 Windows 7电脑和最有可能的SD卡都在读卡器中,因为大多数摄像头没有显示驱动器号(这是我问题的一部分)Batch file 创建批处理文件以将图片复制到网络驱动器,batch-file,windows-7,camera,copy,multi-user,Batch File,Windows 7,Camera,Copy,Multi User,如何创建一个批处理文件,将文件从相机复制到命令行提示的目录 文件夹结构示例:{共享驱动器启动文件夹}[复制后删除图片] 我想让这项工作,以复制照片从不同的相机到一个共享文件夹,并有它所有的排序按年份,然后月份,最后按用户提示的名称。我只知道很少的命令行命令,所有的开关和%。。我很快就迷路了 Windows 7电脑和最有可能的SD卡都在读卡器中,因为大多数摄像头没有显示驱动器号(这是我问题的一部分) 我希望这会有所帮助。使用net Use命令将windows共享映射到类似X:\的驱动器,然后使用
我希望这会有所帮助。使用
net Use
命令将windows共享映射到类似X:\
的驱动器,然后使用
<代码> xCope>代码>用适当的参数复制文件。
< P>就像我在我的评论中所说的,你的问题是<强>非常宽泛< /强>有很多事情要考虑。我编写了一个批处理文件,多年来我一直在许多版本的Windows上使用该文件从SD卡下载我的图片。它做得很好,但没有考虑到两个不同的SD卡上可能有相同的图片名称,即使它们是不同的图片。它只是跳过目标文件夹中已下载的具有相同文件名的图片 我不会为您编写代码,我现在也没有时间帮助您学习批处理文件语言,但我至少可以发布我使用的两个批处理文件,以便您可以看到我用于完成您尝试的操作的一些技术 我在SendTo
文件夹中创建了一个指向DownloadPictures.bat
的快捷方式,这样当我将SD卡插入读卡器时,我可以将SD卡上的images文件夹发送到快捷方式,它会下载所有图片,并根据拍摄的年/月/日将它们分成文件夹。然后,它使用explorer.exe
打开每个不同的目标文件夹。CMD窗口在下载过程中没有显示任何内容(即,没有任何内容回显到窗口),但是,标题显示总体进度和当前图像文件大小(例如,“1/300 7341254字节”)
为了从文件日期中grep年、月和日,我使用了另一个我编写的批处理文件,名为SubStr.bat
,它允许我获取任何DOS命令输出的子字符串,并将其分配给变量。您必须使用延迟的命令行扩展才能使一切正常工作
请记住,这并不是你的问题的解决方案,而是一个简单的例子,展示了如何做一些你正在问的事情——这样你就可以在自己的解决方案中使用它作为参考
下载图片.bat
蝙蝠
谢谢James L和用户 詹姆斯: 帖子1:我想让别人帮我做,但那样我就什么也学不到了。不管你叫我放弃,我有一个工作计划 帖子2:非常有用的帖子。它不仅有代码(我工作没问题),你还描述了你是如何使用它的。第一个代码需要我花一段时间来解码什么是什么以及你是如何做到的。第二段代码非常有用,它有很好的文档记录,我更了解其中的内容 用户: 这就是我用来让我的程序运行的东西。我必须保持简单:) 谢谢你们两位对这个问题的帮助 詹姆斯:非常感谢你在第二篇文章中提供的所有代码和有用的信息 这是将图片从SD卡复制到特定用户命名文件夹的最终工作代码,按年份、月份、项目名称排序。这将SD驱动器设置为驱动器号“F:”您可以将其更改为所需,或删除“@set cameradrive=F:”并从上面的行中删除“REM”,它将提示用户输入驱动器号。它接受用户输入,并使其全部大写,以使文件夹看起来更干净。需要注意的一点是:如果文件夹名中有空格,则此操作无效。我必须想办法解决这个问题(我会在这里发布一个问题)。然后,它会在资源管理器中打开文件夹,以便您可以验证一切是否正常。选中后,您可以按“y”键并按enter键删除SD卡上的文件。如果不想删除它们,请按“n”并按enter键。这会将SD卡上的每张照片复制到嵌套文件夹中,因此如果你有多张照片,你想去不同的地方,这对你不起作用。此外,如果您的图片不是jpg,则只需将“SET type=”更改为您的文件类型即可。我在SD卡的根目录中放置了一个名为“USB弹出器”的程序,这样当批处理文件完成时,它会自动安全地从windows中删除该卡
@ echo on
@ SET type=jpg
@ SET userfolder=C:
@cd /dy:\landis\public\am_class
@REM SET /P cameradrive=Enter Camera Drive Letter (ie D:) and hit Enter:
@SET cameradrive=F:
set /p foldername=Type Folder name and hit Enter:
@REM This makes everything uppercase.
@ SETLOCAL ENABLEDELAYEDEXPANSION
@ SET _SAMPLE="%foldername%"
@ CALL :UCase _SAMPLE _RESULTS
@ ECHO.%_RESULTS%
@ CALL :LCase _SAMPLE _RESULTS
@ ECHO.%_RESULTS%
@ ENDLOCAL
@ GOTO:EOF
@ :LCase
@ :UCase
@ :: Converts to upper/lower case variable contents
@ :: Syntax: CALL :UCase _VAR1 _VAR2
@ :: Syntax: CALL :LCase _VAR1 _VAR2
@ :: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
@ :: _VAR2 = NAME of variable to hold the converted value
@ :: Note: Use variable NAMES in the CALL, not values (pass "by reference")
@ SET _UCase=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
@ SET _LCase=a b c d e f g h i j k l m n o p q r s t u v w x y z
@ SET _Lib_UCase_Tmp=!%1!
@ IF /I "%0"==":UCase" SET _Abet=%_UCase%
@ IF /I "%0"==":LCase" SET _Abet=%_LCase%
@ FOR %%Z IN (%_Abet%) DO SET _Lib_UCase_Tmp=!_Lib_UCase_Tmp:%%Z=%%Z!
@ SET %2=%_Lib_UCase_Tmp%
@REM GOTO:EOF
@REM
@ SET foldername=%_RESULTS%
@REM SETTING THE YEAR AND MONTH VARIABLES
@ SET yyyy=%date:~10,4%
@ SET mm=%date:~4,2%
@REM CREATING THE FOLDERS WITH THE NAMES AND NESTING THEM CORRECTLY
@ mkdir %yyyy%
@ cd %yyyy%
@ mkdir "MSU Orders"
@ cd "MSU Orders"
@ mkdir %mm%
@ cd %mm%
@ mkdir "%foldername%"
@ cd "%foldername%"
@REM COPY THE CONTENTS OF THE CAMREA PIC FOLDER TO THE NEW FOLDER
@ xcopy /e /v %cameradrive%\DCIM\100NIKON "\\landis\public\am_class\%yyyy%\%mm%\%foldername%\"
@ explorer.exe \\landis\public\am_class\%yyyy%\%mm%\%foldername%\
@REM Delete the originals prompt and then actions
@ SET /P delete=Delete Original Photos from Camera (y/n)?
@ IF /I %delete%==y GOTO :dely
@ IF /I %delete%==n GOTO :deln
@ GOTO :deln
@ :dely
@ cd /d%cameradrive%\DCIM\100NIKON
@ del /q *.*
@ GOTO :done
@ :deln
@ GOTO :done
@ :done
@ cd /dc:\
@ F:\USB_Disk_Eject.exe /removethis
@ pause
你的问题很广泛,有很多活动部分(变量)。因为您对批处理文件语言没有很好的掌握,所以您可能应该雇佣一些人来为您编写代码。
@echo off
setlocal ENABLEDELAYEDEXPANSION
cd /d c:\
title Counting the files to download...
set _total=0
for /f "delims=" %%i in ('dir %1 /a-d /b /s') do set /a _total+=1
set _cnt=0
for /f "delims=" %%i in ('dir %1 /a-d /b /s') do (
set /a _cnt+=1
if /I "%%~xi" neq ".ctg" (
title !_cnt!/%_total%: %%i - %%~zi bytes
call substr "echo %%~ti" _date 0 n n "" sub 0 10
call substr "set _date" _year 0 n n "" end 4
call substr "set _date" _month 0 n n "" sub 6 2
call substr "set _date" _day 0 n n "" sub 9 2
set _dir=Q:\Photographs\Downloads\!_year!.!_month!.!_day!
md !_dir! > nul 2>&1
if not defined _old_dir set _old_dir=!_dir!
if "!_dir!" neq "!_old_dir!" (explorer !_dir!&set _old_dir=!_dir!)
if not exist !_dir!\%%~nxi copy %%i !_dir! > nul 2>&1
)
)
explorer !_dir!
echo All the pictures in directory %1 have been downloaded.
endlocal
@echo off
if "%7"=="" goto Help
:ExtractString
:: Remove the first and last " and convert all "" to ".
set __command_=%1
set __command_=%__command_:""="%
set __command_=%__command_:~0,-1%
set __command_=%__command_:~1%
:: Execute the command and direct the output to a unique file.
%__command_% > %TEMP%\_záfileáz_
:: Extract the specified line from the output file. (Note: You can't use 'skip'
:: with a value of '0'.) I used '«' as the delimiter because it is a character
:: that I will never encounter and this will ensure that I get the whole line
:: returned from the 'for' statement.
if "%3"=="0" (
for /f "delims=«" %%i in (%TEMP%\_záfileáz_) do if not defined _závaráz_ (set _závaráz_=%%i)
) else (
for /f "skip=%3 delims=«" %%i in (%TEMP%\_záfileáz_) do if not defined _závaráz_ (set _závaráz_=%%i)
)
if /i "%7"=="all" goto Finish
if /i "%7"=="sub" set _závaráz_=!_závaráz_:~%8,%9!
if /i "%7"=="end" set _závaráz_=!_závaráz_:~-%8!
:Finish
:: Kill spaces, quotes.
if /i "%4"=="y" set _závaráz_=%_závaráz_: =%
if /i "%5"=="y" set _závaráz_=%_závaráz_:"=%
:: Remove unwanted characters (pad the front with an unlikely string so that the
:: FOR statement will never complain because of an empty set). The %%~i notation
:: strips quotes out of the string and spaces are delimiters. This is why they
:: each (spaces and quotes) have their own parameters above...
set __remove_=%6
set __remove_=ßa¯¦¯aß %__remove_:~1%
set __remove_=%__remove_:~0,-1%
set __remove_=%__remove_:""="%
for %%i in (%__remove_%) do set _závaráz_=!_závaráz_:%%~i=!
:: Set the output variable.
set %2=!_závaráz_!
:Cleanup
set _závaráz_=
del %TEMP%\_záfileáz_
set __command_=
set __remove_=
goto TheEnd
:Help
echo.
echo SubStr
echo ================================================================================
echo.
echo Syntax:
echo.
echo SubStr ["command"] [output variable] [Lines to Skip] [Remove Spaces]
echo [Remove Quotes] [Remove Other] [action [var1] [var2]]
echo.
echo Parameters:
echo.
echo Command - The command that creates the output characters. If the
echo command includes calling another batch file, issue the
echo command by using the 'call' function
echo (e.g., "call another.bat"). When your command is passed,
echo it must be enclosed in quotes. If part of the command needs
echo to also have quotes (i.e., for long filenames), the strings
echo within the command that need to be quoted need to be double
echo quoted (e.g., "dir ""c:\win 2000\notepad.exe"" /x"). When
echo the command is executed, the initial and final quotes will
echo be stripped off and all sets of double quotes ("") will be
echo replaced with single quotes (").
echo.
echo Output Variable - The name of the variable to use (set var=copied text).
echo.
echo Lines to Skip - The number of lines before the line from which you want to
echo copy text.
echo.
echo Remove Spaces - Removes spaces out of the copied text.
echo.
echo Remove Quotes - Removes quotes from the copied text.
echo.
echo Remove Other - A string of strings that should be removed from the copied
echo text. The set of strings or characters must be enclosed in
echo a single set of double quotes. At times, some characters
echo may not be elimated (e.g., a comma) unless it too is
echo enclosed in quotes. To do this, the quotes must be doubled.
echo For example: "a b c d "","" e f h"
echo.
echo Action - Action to perform:
echo All - Copies entire string.
echo Sub - Extracts part of the string where var1 is the
echo starting position and var2 is the number of
echo characters to copy. var1 is zero based. A negative
echo value for var2 omits the specified number of
echo characters from the end of the string.
echo End - Only extracts the specified number of characters
echo from the end of the string (specified by var1).
echo.
echo Example:
echo.
echo SubStr "dir c:\windows\system32\notepad.exe /-c" _filesize 5 y n "" sub 20 18
echo.
echo This command assigns the size of notepad.exe to the variable _filesize.
echo Try running it and then type 'set _' at the command prompt.
echo.
echo Notes:
echo.
echo Make sure delayed command line expansion is enabled in the calling batch file
echo via the "setlocal ENABLEDELAYEDEXPANSION" command, or enable it globally by
echo editing the registry as follows (and then reopen your CMD windows):
echo.
echo Location: HKEY_CURRENT_USER\Software\Microsoft\Command Processor
echo Item: DelayedExpansion
echo Type: dword
echo Value: 1
echo.
echo ================================================================================
echo.
:TheEnd
@ echo on
@ SET type=jpg
@ SET userfolder=C:
@cd /dy:\landis\public\am_class
@REM SET /P cameradrive=Enter Camera Drive Letter (ie D:) and hit Enter:
@SET cameradrive=F:
set /p foldername=Type Folder name and hit Enter:
@REM This makes everything uppercase.
@ SETLOCAL ENABLEDELAYEDEXPANSION
@ SET _SAMPLE="%foldername%"
@ CALL :UCase _SAMPLE _RESULTS
@ ECHO.%_RESULTS%
@ CALL :LCase _SAMPLE _RESULTS
@ ECHO.%_RESULTS%
@ ENDLOCAL
@ GOTO:EOF
@ :LCase
@ :UCase
@ :: Converts to upper/lower case variable contents
@ :: Syntax: CALL :UCase _VAR1 _VAR2
@ :: Syntax: CALL :LCase _VAR1 _VAR2
@ :: _VAR1 = Variable NAME whose VALUE is to be converted to upper/lower case
@ :: _VAR2 = NAME of variable to hold the converted value
@ :: Note: Use variable NAMES in the CALL, not values (pass "by reference")
@ SET _UCase=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
@ SET _LCase=a b c d e f g h i j k l m n o p q r s t u v w x y z
@ SET _Lib_UCase_Tmp=!%1!
@ IF /I "%0"==":UCase" SET _Abet=%_UCase%
@ IF /I "%0"==":LCase" SET _Abet=%_LCase%
@ FOR %%Z IN (%_Abet%) DO SET _Lib_UCase_Tmp=!_Lib_UCase_Tmp:%%Z=%%Z!
@ SET %2=%_Lib_UCase_Tmp%
@REM GOTO:EOF
@REM
@ SET foldername=%_RESULTS%
@REM SETTING THE YEAR AND MONTH VARIABLES
@ SET yyyy=%date:~10,4%
@ SET mm=%date:~4,2%
@REM CREATING THE FOLDERS WITH THE NAMES AND NESTING THEM CORRECTLY
@ mkdir %yyyy%
@ cd %yyyy%
@ mkdir "MSU Orders"
@ cd "MSU Orders"
@ mkdir %mm%
@ cd %mm%
@ mkdir "%foldername%"
@ cd "%foldername%"
@REM COPY THE CONTENTS OF THE CAMREA PIC FOLDER TO THE NEW FOLDER
@ xcopy /e /v %cameradrive%\DCIM\100NIKON "\\landis\public\am_class\%yyyy%\%mm%\%foldername%\"
@ explorer.exe \\landis\public\am_class\%yyyy%\%mm%\%foldername%\
@REM Delete the originals prompt and then actions
@ SET /P delete=Delete Original Photos from Camera (y/n)?
@ IF /I %delete%==y GOTO :dely
@ IF /I %delete%==n GOTO :deln
@ GOTO :deln
@ :dely
@ cd /d%cameradrive%\DCIM\100NIKON
@ del /q *.*
@ GOTO :done
@ :deln
@ GOTO :done
@ :done
@ cd /dc:\
@ F:\USB_Disk_Eject.exe /removethis
@ pause