1.

Solve : Rename first file with structure name.?

Answer»

Hi All,

I have one folder with a lot of files, all them use same structure NAME example (bird_happy_1234.txt, bird_happy_1235.txt,bird_happy_1236.txt) only _1234 change.
I need to rename only the first one and them move this file to another folder.
The new name its the same EVERY time because this i want to move to another folder after i rename.
After a renamed the file i know its not a problem to move because the file have same name every time.

Best regards,
                  DiogoI have this solution right now its work.

Code: [Select]for /F %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
move /-y "C:\Users\Diogo\Desktop\Tests_Batch\%LAST%" "C:\Users\Diogo\Desktop\Tests_Batch\Processed"
copy /-y "C:\Users\Diogo\Desktop\Tests_Batch\Processed\%LAST%"  "C:\Users\Diogo\Desktop\Tests_Batch\Importing"
del C:\Users\Diogo\Desktop\Tests_Batch\Importing\imp_t.txt
rename C:\Users\Diogo\Desktop\Tests_Batch\Importing\%LAST% imp_t.txt
call "C:\Users\Diogo\Desktop\Tests_Batch\Test.bat"

But i have one issue, when my folder its empty from .txt files the code copy the .bat file.Try this:

Code: [Select]for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
if not "%LAST%"=="%~nx0" (
move /-y "C:\Users\Diogo\Desktop\Tests_Batch\%LAST%" "C:\Users\Diogo\Desktop\Tests_Batch\Processed"
copy /-y "C:\Users\Diogo\Desktop\Tests_Batch\Processed\%LAST%"  "C:\Users\Diogo\Desktop\Tests_Batch\Importing"
del C:\Users\Diogo\Desktop\Tests_Batch\Importing\imp_t.txt
rename C:\Users\Diogo\Desktop\Tests_Batch\Importing\%LAST% imp_t.txt
call "C:\Users\Diogo\Desktop\Tests_Batch\Test.bat"
)
If it doesn't work, add 'echo %LAST%' to the END and post what it says.  %~0 will need to be formatted the same way for the EXCLUSION to work.Hi, your code help me change the old one, i used one more folder and when this folder empty i used if not.
Thx very much!

final code:
Code: [Select]for /f %%i in ('dir C:\Users\Diogo\Desktop\Tests_Batch\Incoming\*.txt /b/a-d/od/t:c') do set LAST=%%i
if not "%LAST%"=="" (
move /-y "C:\Users\Diogo\Desktop\Tests_Batch\Incoming\%LAST%" "C:\Users\Diogo\Desktop\Tests_Batch\Processed"
copy /-y "C:\Users\Diogo\Desktop\Tests_Batch\Processed\%LAST%"  "C:\Users\Diogo\Desktop\Tests_Batch\Importing"
del C:\Users\Diogo\Desktop\Tests_Batch\Importing\imp_t.txt
rename C:\Users\Diogo\Desktop\Tests_Batch\Importing\%LAST% imp_t.txt
)



Discussion

No Comment Found