Page 1 of 1

[Solved] Convert a windows batch script to .xys syntax?

Posted: 07 Feb 2011 21:50
by highend
Hi,

I'm trying to convert a batch script to XYplorer's .xys format.

%target_temp% was defined (%temp%\<datea dd.mm.yyyy_hh-mm-ss>
as well as the target_1 & target_2 variables.

I've done the first part of converting successfully but I'm stuck on the second part:

Code: Select all

set counter=0

for /f %%i in ('dir %target_temp% /ad /od /b') do (
	set /a counter+=1
	
	rmdir /s /q "%target_1%\%%i"
	rmdir /s /q "%target_2%\%%i"
	xcopy "%target_temp%\%%i" "%target_1%\%%i" /s /e /i
	xcopy "%target_temp%\%%i" "%target_2%\%%i" /s /e /i
)

REM Clean up
if %counter% gtr 0 (
	rd "%target_temp%" /s /q
	del %archiv%
)
The /for part reads in a list of all subfolders (previously extracted via winrar from a .zip file) and will
delete corresponding folders (with same names) in both of the target_x dirs. After that these folders
will be copied into the target dirs.

After this procedure it'll delete the temp folder + the archive.zip as well.

Any help is appreciated :)

Regards,
Highend

Re: Convert a windows batch script to .xys syntax?

Posted: 08 Feb 2011 12:22
by highend
Was able to solve it myself :)

Probably not the shortest or smartest way but without any coding experience. At least, it works as expected!

Code: Select all

	setting('BackgroundFileOps', 0); //From here delete & copy synchronously
	$archive_temp_folders = listfolder($archive_temp, , 2 + 4, "|"); //Only get the basenames of the folders

	if ($archive_temp_folders>"")
	{
		$loop = 1;
		$count = 0;
		$array = "";
		while(true)
		{
			$entries = gettoken($archive_temp_folders, $loop, "|");
			if ($entries == "") {break;}
			$cur_array_element = $entries;
			incr $count;
			delete 1, 0, $target_1\$cur_array_element;
			delete 1, 0, $target_2\$cur_array_element;
			copyto $target_1, $archive_temp\$cur_array_element, , 2;
			copyto $target_2, $archive_temp\$cur_array_element, , 2;
			incr $loop;
		}
	}

	delete 0, 0, $archive_temp;
	delete 1, 0, $archive;