Computing.Net > Forums > Disk Operating System > Copy, increment, and delete file

Copy, increment, and delete file

Reply to Message Icon

Original Message
Name: Sach
Date: March 28, 2007 at 02:25:12 Pacific
Subject: Copy, increment, and delete file
OS: Win 2003
CPU/Ram: 3G
Model/Manufacturer: Compaq
Comment:

Hi,

Please help, I do not know much about DOS scripting.

I require a script that copies and renames a file to a new location and increments the file name.
eg, c:\alert_file to c:\files\alert_file_1
.The original alert file is then deleted, but only if the new one has been created.


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: March 28, 2007 at 03:27:00 Pacific
Reply: (edit)

::== i2.bat
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=3 delims=_" %%a in ('dir /s/b/a-d alert_file*') do (
set /a N=%%a
)
set /a N+=1
echo move c:\alert_file c:\files\alert_file_!N!
::==


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: March 28, 2007 at 04:16:17 Pacific
Reply: (edit)

CORRECTION

::== i4.bat
@echo off
setLocal EnableDelayedExpansion

pushd c:\files
for /f "tokens=3 delims=_" %%a in ('dir /b/a-d/od alert_file*') do (
set /a N=%%a
)
set /a N+=1
echo move c:\alert_file c:\files\alert_file_!N!
popd
::==


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 3
Name: Sach
Date: March 28, 2007 at 11:00:18 Pacific
Reply: (edit)

Thanks, but im getting:

The system cannot find the path specified.
File Not Found
move c:\alert_file c:\files\alert_file_1

The files definately exist....


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: March 28, 2007 at 11:31:40 Pacific
Reply: (edit)

"The files definately exist"

try:

dir c:\files\alert_file*


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: Sach
Date: March 30, 2007 at 03:38:35 Pacific
Reply: (edit)

I think im bein thick...But let me just explain the issue in more detail.

I have a file in c:\alerts\alert.txt and I want to move it to a folder called c:\old_alerts\alert_NUMBER.txt, The 'NUMBER' will increment.

The original alert file is then deleted, but only if the new one has been created.

Is this what your script will do?
Sorry about this..


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: March 30, 2007 at 04:31:37 Pacific
Reply: (edit)

No problem. In order for the script below to work you need to have one 'dummy' file in the target directory. You can create the dummy like this:

type nul> c:\old_alerts\alert_0

do that just once, then try this script:

::== increm6.bat
@echo off
setLocal EnableDelayedExpansion

pushd c:\old_alerts
for /f "tokens=2 delims=_" %%a in ('dir /b/a-d/od alert_*') do (
set /a N=%%a
)
set /a N+=1
move c:\alert_file c:\old_alerts\alert_!N!
popd
::==


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 7
Name: Mike Newcomb
Date: March 30, 2007 at 18:48:42 Pacific
Reply: (edit)

Dear Mechanix

Sach advises o/s as Win 2003. What is this?

Does dos script allow for directory and/or file names greater than 8 characters, which he appears to be attempting.

If so, do they have to be truncated with the ~ character?

Regards - Mike

Good Luck - Keep us posted.


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Copy, increment, and delete file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge