1.

Solve : move each file to a separate folder?

Answer»

hi
i want to  search  my  current folder and move all  of  (.exe) files to  a separate folder (each  file into  a unique folder )
and so
1- if there is not that folder exist create it
2-  rename each  folder to  file  name that has been  moved
3-  then  rename each  (.exe) file to  setup.exe

can you help me with that?
can  you  write some scripts for a batch  file?
thankstry this:
Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%A in ('dir /B *.exe') do (
set fileName=%%~nA
md !fileName!
move %%A !fileName!\setup.exe
)
pauseDon't  move .exe ( programs ) that are essential for the OS  to operate.

The path to the program cannot be found wnen the OS needs it.

Your OS will crash.  (  such files are usually PROTECTED from such nonsense. )

If you must have a new location, copy and don't move.thanks dear devcom for your fast reply
for testing your scripts i  copied 10 exe file into  a folder and start your program
unfortunately  it can't detect all  of exe files because it made some(5 ) folder  and name them  badly (half name)
and folders are empty  because it can't move files  to  folders  why?
1-files are not read only  and their attribs are clear
2-  some of files have long  separated names  example= windows media player 12
so  there is space in  file names
i  have this error  message  for all  files
Quote

The process cannot access the file because it is being used by another process.
        0 file(s) moved.   
                                                   
i  even  restart my  system  but nothing has changed
 i can  identify  and  move all  of these files with  other batch  files
so  what's wrong? Quote from: mioo_sara on May 30, 2009, 05:27:05 AM
thanks dear devcom for your fast reply
for testing your scripts i  copied 10 exe file into  a folder and start your program
unfortunately  it can't detect all  of exe files because it made some(5 ) folder  and name them  badly (half name)
and folders are empty  because it can't move files  to  folders  why?
1-files are not read only  and their attribs are clear
2-  some of files have long  separated names  example= windows media player 12
so  there is space in  file names
i  have this error  message  for all  files                                                   
i  even  restart my  system  but nothing has changed
 i can  identify  and  move all  of these files with  other batch  files
so  what's wrong?
First off, files that are being used by another process or computer can't be modified or moved until whatever else is using them has stopped. Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%A in ('dir /b *.exe') do (
set fileName=%%~nA
md "!fileName!"
taskkill /F /IM "%%A"
echo move "%%A" "!fileName!\setup.exe"
)
pause
try now if this will work REMOVE echo from 8 line Quote
First off, files that are being used by another process or computer can't be modified or moved until whatever else is using them has stopped.

so  why  i can  move them  with  below SCRIPT?

Quote
echo off & setLocal EnableDelayedExpansion


for /f "tokens=* delims= " %%a in ('dir/s/b/a-d *.exe') do (
move "%%a" "home"
)
wow !! it worked devcom  thanks my  man
although i  saw error message for all  files  but this time all  the folders have created and they  are all  renamed
and exe files are moved and renamed
wonderful
now dear devcom if its ok  with  you  can  you  help  me with  this 2 last request?
question 1=
there are some more files (.com and .txt) files in  this folder next to  the others (exe file)
now i  wnat them  to  be moved to one folder (each  one) so  how can  we change above script?
i  changed 
Quote
for /f "tokens=*" %%A in ('dir /b *.exe') do (
to
for /f "tokens=*" %%A in ('dir /b *.exe *.com *.txt') do (

so  is there any  problem with  that? so  what about this  line? echo move "%%A" "!fileName!\setup.exe"
this command rename all  file to  setup.exe so  what can  i do for .txt and .com  files?
txt  file should be rename to readme.txt
.com files should be rename to setup.com
question 2= some of files have "update" or "uninstall" word in  their names
these kind of files should be renamed to update or uninstall (ignore to  rename them  to setup)

thanks my  dear devcombut you want to do this the same way as .exe for .txt and c.om ? so you have file test1234.txt and you want to make test1234 folder and put the .txt file there as readme.txt ?sorry  dear devcom for answering late
yes i  want the exact of operation  that you  mentioned
thanks i am  waiting Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%A in ('dir /b *.exe *.txt *.com') do (
md "!fileName!" 2>nul

set fileName=%%~nA
::set fileName=!fileName:update=!
::set fileName=!fileName:uninstall=!
set fileExt=%%~xA

if "!fileExt!" equ ".txt" (set moveName=readme) ELSE (set moveName=setup)

call :FIND "%%A"

echo move "%%A" "!fileName!\!moveName!!fileExt!

)
pause
exit

:FIND
set find=%~1
echo.%find% |findstr /I "uninstall" >nul && set moveName=Uninstall
echo.%find% |findstr /I "update" >nul && set moveName=Update
exit /b
this should work

PS you can remove :: from 8,9 line to make folders without update or uninstall word ,i mean if you have file: 'test update.exe' it will create 'test' folder instead of 'test update' folder if you delate ::

PS.2 ofc you need to remove echo if this will workWhy does "Mioo_Sara" want to move  ".exe" files into separate unique folder?   What is the goal of such a strange movement of .exe files?

What is Mioo_sara  trying to accomplish? 



Quote from: mioo_sara on May 30, 2009, 03:45:59 AM
hi
i want to search my  current folder and move all  of  (.exe) files to  a separate folder (each  file into  a unique folder )
and so
1- if there is not that folder exist create it
2-  rename each  folder to  file  name that has been  moved
3-  then  rename each  (.exe) file to  setup.exe

can you help me with that?
can  you  write some scripts for a batch  file?
thanks
maybe he created 1000 apps and now he want to clean his computer ? Quote from: devcom on May 30, 2009, 03:51:10 PM
maybe he created 1000 apps and now he want to clean his computer ?

If clean the computer  of .exe files, then del is better than move.

The movement of .exe to a unique folder was not restricted to .exe files created by the user.

It is and was a nonsense and dangerous exercise to move .exe files to a unique folder.billrich is right, this is odd.


Discussion

No Comment Found