batch input to organize

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
blackpete
Posts: 36
Joined: 31 Jul 2012 16:14

Re: batch input to organize

#16 Post by blackpete » 01 Aug 2012 13:26

Liviu, I tried your suggestion to see if it would work.

" but changing "move /-y *.%%x" to "move /-y %drive%\*.%%x" will move the files _from_ the root of the selected drive, instead"

but, I get this "The filename, directory name, or volume label syntax is incorrect.

blackpete
Posts: 36
Joined: 31 Jul 2012 16:14

Re: batch input to organize

#17 Post by blackpete » 01 Aug 2012 13:28

it was changed to what you said. Did I do it right?

if not exist %drive%\ORGANIZED\DOCUMENTS md %drive%\ORGANIZED\DOCUMENTS
for %%x in (doc txt docx pdf rtf vsd wpd wri) do move /-y %drive%\*.%%x\ORGANIZED\DOCUMENTS

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: batch input to organize

#18 Post by Squashman » 01 Aug 2012 13:38

The FOR LOOPS are looking for files in the current working directory.

You will need to change to the drive letter you want to process first.
You can just put the Drive Letter on a line by itself or use the PUSHD command.

blackpete
Posts: 36
Joined: 31 Jul 2012 16:14

Re: batch input to organize

#19 Post by blackpete » 01 Aug 2012 13:46

Don´t get you Squashman, what should I change "for %%x in " to what?

The code is there, will be easy if you change it and highlight it.

Sorry!

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: batch input to organize

#20 Post by Squashman » 01 Aug 2012 14:00

Before your first IF not exist you can do this

Code: Select all

%drive%

or

Code: Select all

pushd %drive%

If you use the pushd then put the POPD command after your last FOR command.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: batch input to organize

#21 Post by foxidrive » 01 Aug 2012 14:02

As an intellectual exercise it's good - but if you ran that on my machine and recursed through folders then I'd break your nose. ;)

What I'm trying to say is that the purpose is fine if it is your machine, but to do that on someone else's machine (who may have things sorted in their own way) then it could be quite destructive.

The way I would approach this as an exercise is to use pushd to change the working directory to the root of the drive.
EG: If drive is set to "d:" without the quotes then use this:

Code: Select all

pushd "%drive%\"
:: run your code here
popd


Squashman has just posted this same - but I'll post this anyway.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: batch input to organize

#22 Post by Liviu » 01 Aug 2012 14:35

First off, the pushd/popd suggestion has my vote, too.

blackpete wrote:for %%x in (doc txt docx pdf rtf vsd wpd wri) do move /-y %drive%\*.%%x\ORGANIZED\DOCUMENTS
Just to clarify, that's wrong, and it's not what I said. You had
"move /-y *.%%x %drive%\ORGANIZED\DOCUMENTS"
before, and if you replaced ""move /-y *.%%x" with "move /-y %drive%\*.%%x", then you'd get
"move /-y %drive%\*.%%x %drive%\ORGANIZED\DOCUMENTS"
which was my suggestion. Note however that once you use pushd/popd, instead, you do no need this change.

foxidrive wrote:What I'm trying to say is that the purpose is fine if it is your machine, but to do that on someone else's machine (who may have things sorted in their own way)

You are right, of course. Suppose one had a saved .html page linking to a .jpg also saved in the same directory. After the move, the .html would no longer work, and the .jpg would be orphaned. On the other hand, users who routinely save everything to the root directory most likely don't have things "sorted in their own way" ;-)

Liviu

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: batch input to organize

#23 Post by Squashman » 01 Aug 2012 14:54

Liviu wrote:On the other hand, users who routinely save everything to the root directory most likely don't have things "sorted in their own way" ;-)

Liviu

But that makes it easier to find evrything!
:mrgreen:

blackpete
Posts: 36
Joined: 31 Jul 2012 16:14

Re: batch input to organize

#24 Post by blackpete » 01 Aug 2012 20:00

Okay guys, I like the gathering of the forum´s members. sorry Liviu if I didn´t get your instructions right, and Liviu you are also right with the html example that you mention, but this batch is not for advance users that have their files sorted in their own way, this batch is for everyday people that don´t have the time to organize their files, this does not go thru folders, it just take all the loose files, on the desktop, or the root of D:, or a flashcard.

Back to the blackboard!

blackpete
Posts: 36
Joined: 31 Jul 2012 16:14

Re: batch input to organize

#25 Post by blackpete » 01 Aug 2012 21:25

Last but not least!
I tried the pushd "%drive%\" before the code and popd at the end, did the job, but kept on showing two things that I don´t need.
One was the "A duplicate file name exist, or the file cannot be found.", and the other thing that shows now is the list of the files that were moved.
So I took off the " pushd "%drive%\" before the code and popd at the end", and added the "move 2>nul" to avoid the "A duplicate file name exist, or the file cannot be found.".

But still shows the list of files that were moved, where do they come from?

blackpete
Posts: 36
Joined: 31 Jul 2012 16:14

Re: batch input to organize

#26 Post by blackpete » 01 Aug 2012 21:27

sorry, I forgot to show you the code.


set drive=
set /p drive= which drive you want to organize first?
if "%drive%"=="1" (set "drive=C:"
)else if "%drive%"=="2" (set "drive=D:"
)else if "%drive%"=="3" (set "drive=E:"
)else if "%drive%"=="4" (set "drive=F:"
)else if "%drive%"=="5" (set "drive=G:"
)else if "%drive%"=="6" (set "drive=H:"
)else if "%drive%"=="7" (set "drive=I:"
)else if "%drive%"=="8" (goto :eof
) else goto :menu


if not exist %drive%\ORGANIZED\DOCUMENTS md %drive%\ORGANIZED\DOCUMENTS
for %%x in (doc txt docx pdf rtf vsd wpd wri) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\DOCUMENTS
if not exist %drive%\ORGANIZED\PHOTOS md %drive%\ORGANIZED\PHOTOS
for %%x in (bmp gif jpg jped png tiff psd psp wmf) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\PHOTOS
if not exist %drive%\ORGANIZED\MUSIC md %drive%\ORGANIZED\MUSIC
for %%x in (mp3 wav wma mid m4a au ape) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\MUSIC
if not exist %drive%\ORGANIZED\POWERPOINT md %drive%\ORGANIZED\POWERPOINT
for %%x in (ppt pptx) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\POWERPOINT
if not exist %drive%\ORGANIZED\EXCEL md %drive%\ORGANIZED\EXCEL
for %%x in (xls xlsx) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\EXCEL
if not exist %drive%\ORGANIZED\VIDEO md %drive%\ORGANIZED\VIDEO
for %%x in (wmv avi mov flv m4v rmvb mpeg) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\VIDEO
if not exist %drive%\ORGANIZED\INTERNET-FILES md %drive%\ORGANIZED\INTERNET-FILES
for %%x in (htm html) do move 2>nul /-y %drive%\*.%%x %drive%\ORGANIZED\INTERNET-FILES

ECHO .....................................................................
ECHO REMEMBER, LOOK FOR FOLDER "ORGANIZED" IN THE DRIVE YOU SELECTED
ECHO .....................................................................
pause

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: batch input to organize

#27 Post by Squashman » 01 Aug 2012 21:30

Do you have this at the top of your batch file?
@echo off

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: batch input to organize

#28 Post by foxidrive » 01 Aug 2012 22:33

blackpete wrote:Last but not least!
I tried the pushd "%drive%\" before the code and popd at the end, did the job, but kept on showing two things that I don´t need.
One was the "A duplicate file name exist, or the file cannot be found."


The pushd doesn't cause that. The problem can't be a duplicate filename if it is working from a single folder, so it must be a hidden or system file in the folder

, and the other thing that shows now is the list of the files that were moved.
So I took off the " pushd "%drive%\" before the code and popd at the end", and added the "move 2>nul" to avoid the "A duplicate file name exist, or the file cannot be found.".

But still shows the list of files that were moved, where do they come from?


use this

move source target >nul

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: batch input to organize

#29 Post by Ed Dyreen » 01 Aug 2012 22:35

'
Hi blackpete,

I tried to understand what you were after, this is the best I could come up with.

Code: Select all

@echo off &prompt $G &setlocal enableDelayedExpansion

:init ()
:: (
       call :menu %*

       echo.Is this what you want ?
       pause
:: )
exit /b 0

:menu ()
:: (
       cls
       echo.
       set "?=C,D,E,F,G,H,I" &set "$=" &set /p "$= which drive you want to organize first[!?!]?"
       ::
       if defined $ if /i "!?!" neq "!?:%$%=!" (

              set "$drive=!$!:"
              call :organize "()"
       ) else goto :menu "()"
:: )
exit /b 0

:organize ()
:: (
       for /f "usebackq tokens=1 delims==" %%? in ( `2^>nul set #` ) do set "%%~?="
       ::
       set      "#DOCUMENTS=doc,txt,docx,pdf,rtf,vsd,wpd,wri"
       set         "#PHOTOS=bmp,gif,jpg,jped,png,tiff,psd,psp,wmf"
       set          "#MUSIC=mp3,wav,wma,mid,m4a,au,ape"
       set     "#POWERPOINT=ppt,pptx"
       set          "#EXCEL=xls,xlsx"
       set          "#VIDEO=wmv,avi,mov,flv,m4v,rmvb,mpeg"
       set "#INTERNET-FILES=htm,html"

       2>nul (

              for /f "usebackq tokens=1-2 delims=#=" %%a in (

                     `set #`

              ) do   echo.md "!$drive!\ORGANIZED\%%~a" &for %%? in (

                     %%~b

              ) do   echo.move /-y "!$drive!\*.%%~?" "!$drive!\ORGANIZED\%%~a\"
       )
:: )
exit /b 0


Ed

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: batch input to organize

#30 Post by Liviu » 01 Aug 2012 23:33

Hi Ed, thought the OP was one ">nul" away from having his wish granted, and now you come and ruin everything ;-)

Don't get me wrong, yours is nice and leaner code. However, given the context, I'm afraid it might raise more questions than answer.

Now that you opened the gates, may I also point that:
- "jped" under PHOTOS is a misspelling of "jpeg";
- "docx" under DOCUMENTS, "pptx" under POWERPOINT, "xlsx" under EXCEL, and "html" under INTERNET are redundant except in the rare case of an NTFS volume with NtfsDisable8dot3NameCreation=1 (otherwise for example *.doc will match .docx files, too, due to the short 8.3 name).

Liviu

Post Reply