user3641499
user3641499

Reputation: 13

Sorting files into folders

So I have files that include time and date like this "05_14_2014_17_56_01". I want to sort them into folders by date and not time.

So what I was trying to do was get a for loop to make a directory using only the date, and putting the file in there. However the syntax of these batch files is killing me. It should be pretty simple but im having alot of trouble. Can anyone help me out with this.

I tried something like this initially

setlocal EnableDelayedExpansion
cd C:\Users\****\Downloads\test
for %%i in (*csv) do (set fileName= %%i & echo !fileName! & mkdir !fileName:~0,10%! & move %%i !fileName:~0,10%!)

pause

Upvotes: 0

Views: 72

Answers (1)

Stephan
Stephan

Reputation: 56180

this not only works, but is even better to read:

setlocal EnableDelayedExpansion
for %%i in ("*.csv") do ( 
 set "fileName=%%i" 
 echo !fileName! 
 mkdir "!fileName:~0,10%!"
 copy "%%i" "!fileName:~0,10%!"
)
pause

I only extracted the command & command & command to individual lines.

Ah - and I removed a space, which would make trouble (with your setcommand)

Upvotes: 1

Related Questions