

InterviewSolution
Saved Bookmarks
1. |
Solve : How to move files based on file size with batch file?? |
Answer» <html><body><p>I need to check 10 different Source directories for files and move them to 10 different <a href="https://interviewquestions.tuteehub.com/tag/destination-244461" style="font-weight:bold;" target="_blank" title="Click to know more about DESTINATION">DESTINATION</a> directories. However files over 50Mb I need to move to a BigFile directory and rename the <a href="https://interviewquestions.tuteehub.com/tag/extension-kaya-455373" style="font-weight:bold;" target="_blank" title="Click to know more about EXTENSION">EXTENSION</a> to *.big. I'm new/rusty to batch files but I've created the following script that I can't <a href="https://interviewquestions.tuteehub.com/tag/seem-7258342" style="font-weight:bold;" target="_blank" title="Click to know more about SEEM">SEEM</a> to get working correctly. I'm using it in a windows environment.<br/><br/><br/><br/>echo on<br/><br/>setlocal<br/><br/>set /p directory1=D:\receivingdir\2.16.840.1.113883.3.105.102<br/><br/>set /a size=52428800<br/><br/>set /p newdirectory1=D:\processingdir\Sources\2.16.840.1.113883.3.105.102\In<br/><br/>set /p newdirectory2=D:\BigFileTransport<br/><br/>for %%q in %directory1% do if %%~zq lss %size% move %%q %newdirectory1%<br/><br/><br/>for %%q in %directory1% do if %%~zq geq %size% move %%q %newdirectory2%<br/><br/>pause<br/><br/><br/>Any ideas?Lose the /p switch from SET. For details of usage of SET command, type SET /? at the prompt. <br/><br/>If any filenames are likely to have spaces you should use quotes<br/><br/>e.g.<br/><br/> Code: <a>[Select]</a>move "%%q" %newdirectory1%<br/>FOR syntax needs correction<br/><br/> Code: <a>[Select]</a>for /f "delims=" %%q in ( ' dir /b /a-d "%directory1%\*.*" ' ) do if %%~zq lss %size% move "%%q" %newdirectory1%<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/thanks-665909" style="font-weight:bold;" target="_blank" title="Click to know more about THANKS">THANKS</a> Salmon!</p></body></html> | |