Script to read first six characters of a file

Closed
Chuch - Jan 11, 2010 at 02:54 PM
 Chuch - Jan 11, 2010 at 03:16 PM
Hello,

I am trying to write a script to read the first six characters of a file and move it to a folder in a new directory with the same name as the first six characters in a new directory if the file was created before 01/01/2010. The first six characters of the file are all numeric, and I have some of the directories setup, but hundreds that are not.

example:

file 661920090817135 located in Y:\test\1 will be read in the script, and see the first six characters as 661920, check that it was created before 01/01/2010 and move it into a directory called 661920 located at Y:\test\1\archivedata

Any help would be greatly appreciated.

Thanks,
Chuch.
Related:

1 response

Hello again all,

This is the script I am currently using, but it's not working. If this helps... it wont create the folder if it doesn't exist, and only moves it to a folder with the exact full name of the file.

@echo off
setlocal enabledelayedexpansion
pushd "Y:\Test\1"
for %%j in (*) do (
set name=%%~nj
if exist !name!\ (
move "%%j" "Y:\Test\1\ArchiveData\!name!"
) else (
echo Warning: %%j not moved to !name!: folder does not exist.
)
)
popd
pause
exit
0